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:
parent
b222e4efae
commit
71e8237483
6
vlib/v/checker/tests/assign_expr_undefined_err_i.out
Normal file
6
vlib/v/checker/tests/assign_expr_undefined_err_i.out
Normal 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 | }
|
4
vlib/v/checker/tests/assign_expr_undefined_err_i.vv
Normal file
4
vlib/v/checker/tests/assign_expr_undefined_err_i.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn main() {
|
||||||
|
mut a := []int{init: a}
|
||||||
|
println(a)
|
||||||
|
}
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user