mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: improve error message for invalid property (#9263)
This commit is contained in:
parent
3be78d6777
commit
e229d0c1c3
@ -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 !in [.struct_, .aggregate, .interface_, .sum_type] {
|
||||||
if sym.kind != .placeholder {
|
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 {
|
} else {
|
||||||
if sym.info is table.Struct {
|
if sym.info is table.Struct {
|
||||||
|
18
vlib/v/checker/tests/invalid_property.out
Normal file
18
vlib/v/checker/tests/invalid_property.out
Normal file
@ -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
|
||||||
|
| ~~~
|
6
vlib/v/checker/tests/invalid_property.vv
Normal file
6
vlib/v/checker/tests/invalid_property.vv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
s :=''
|
||||||
|
_ = s.length
|
||||||
|
_ = [1,2].foo
|
||||||
|
|
||||||
|
mut fa := [3,4]!
|
||||||
|
_ = fa.bar
|
Loading…
Reference in New Issue
Block a user