1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check undefined ident of struct (#9164)

This commit is contained in:
yuyi 2021-03-07 21:09:38 +08:00 committed by GitHub
parent f1c4e962f4
commit 1b47e2953d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -1063,6 +1063,9 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
to_lock, pos = c.fail_if_immutable(expr.right)
}
ast.SelectorExpr {
if expr.expr_type == 0 {
return '', pos
}
// retrieve table.Field
c.ensure_type_exists(expr.expr_type, expr.pos) or { return '', pos }
mut typ_sym := c.table.get_final_type_symbol(c.unwrap_generic(expr.expr_type))

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/undefined_ident_of_struct.vv:4:2: error: undefined ident: `f`
2 |
3 | fn get() {
4 | f.a = 'test'
| ^
5 | }
6 |

View File

@ -0,0 +1,9 @@
module main
fn get() {
f.a = 'test'
}
fn main() {
println('hello')
}