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

parser: check undefined variables in array inits (#10746)

This commit is contained in:
yuyi 2021-07-11 08:49:07 +08:00 committed by GitHub
parent b222e4efae
commit 71e8237483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/assign_expr_undefined_err_i.vv:2:23: error: undefined variable: `a`
1 | fn main() {
2 | mut a := []int{init: a}
| ^
3 | println(a)
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
mut a := []int{init: a}
println(a)
}

View File

@ -30,6 +30,17 @@ fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
} }
} }
} }
ast.ArrayInit {
if val.has_cap {
p.check_undefined_variables(exprs, val.cap_expr) ?
}
if val.has_len {
p.check_undefined_variables(exprs, val.len_expr) ?
}
if val.has_default {
p.check_undefined_variables(exprs, val.default_expr) ?
}
}
ast.CallExpr { ast.CallExpr {
p.check_undefined_variables(exprs, val.left) ? p.check_undefined_variables(exprs, val.left) ?
for arg in val.args { for arg in val.args {