checker: add a suggestion for misspelled struct field name errors
parent
f534edc371
commit
11b16a63cf
|
@ -1673,6 +1673,11 @@ pub fn (mut c Checker) selector_expr(mut selector_expr ast.SelectorExpr) table.T
|
|||
c.error('`$sym.source_name` is not a struct', selector_expr.pos)
|
||||
}
|
||||
} else {
|
||||
if sym.kind == .struct_ {
|
||||
sss := sym.info as table.Struct
|
||||
suggestion := util.new_suggestion(field_name, sss.fields.map(it.name))
|
||||
c.error(suggestion.say(unknown_field_msg), selector_expr.pos)
|
||||
}
|
||||
c.error(unknown_field_msg, selector_expr.pos)
|
||||
}
|
||||
return table.void_type
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
vlib/v/checker/tests/unknown_struct_field_suggest_name.vv:11:16: error: type `Points` has no field or method `xxxa`.
|
||||
Did you mean `xxxx`?
|
||||
9 | p := Points{[1], [2], [3]}
|
||||
10 | println('p: $p')
|
||||
11 | for x in p.xxxa {
|
||||
| ~~~~
|
||||
12 | println('x: $x')
|
||||
13 | }
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
struct Points {
|
||||
xxxx []int
|
||||
yyyy []int
|
||||
zzzz []int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
p := Points{[1], [2], [3]}
|
||||
println('p: $p')
|
||||
for x in p.xxxa {
|
||||
println('x: $x')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue