diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 7bf98ce7c9..4c98854b0f 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2335,7 +2335,7 @@ pub fn (mut c Checker) selector_expr(mut selector_expr ast.SelectorExpr) table.T } if sym.kind !in [.struct_, .aggregate, .interface_, .sum_type] { if sym.kind != .placeholder { - c.error('`$sym.name` is not a struct', selector_expr.pos) + c.error('`$sym.name` has no property `$selector_expr.field_name`', selector_expr.pos) } } else { if sym.info is table.Struct { diff --git a/vlib/v/checker/tests/invalid_property.out b/vlib/v/checker/tests/invalid_property.out new file mode 100644 index 0000000000..e7839a42b9 --- /dev/null +++ b/vlib/v/checker/tests/invalid_property.out @@ -0,0 +1,18 @@ +vlib/v/checker/tests/invalid_property.vv:2:7: error: `string` has no property `length` + 1 | s :='' + 2 | _ = s.length + | ~~~~~~ + 3 | _ = [1,2].foo + 4 | +vlib/v/checker/tests/invalid_property.vv:3:11: error: `[]int` has no property `foo` + 1 | s :='' + 2 | _ = s.length + 3 | _ = [1,2].foo + | ~~~ + 4 | + 5 | mut fa := [3,4]! +vlib/v/checker/tests/invalid_property.vv:6:8: error: `[2]int` has no property `bar` + 4 | + 5 | mut fa := [3,4]! + 6 | _ = fa.bar + | ~~~ diff --git a/vlib/v/checker/tests/invalid_property.vv b/vlib/v/checker/tests/invalid_property.vv new file mode 100644 index 0000000000..427c2e7fb7 --- /dev/null +++ b/vlib/v/checker/tests/invalid_property.vv @@ -0,0 +1,6 @@ +s :='' +_ = s.length +_ = [1,2].foo + +mut fa := [3,4]! +_ = fa.bar