parser: make `v := f(v)' an undefined variable error (#8634)

pull/8637/head^2
zakuro 2021-02-08 23:55:01 +09:00 committed by GitHub
parent 03d5bfbc95
commit 8ae23cd89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/assign_expr_undefined_err_h.vv:6:9: error: undefined variable: `n`
4 |
5 | fn main() {
6 | n := f(n)
| ^
7 | println(n)
8 | }

View File

@ -0,0 +1,8 @@
fn f(i int) int {
return i
}
fn main() {
n := f(n)
println(n)
}

View File

@ -25,6 +25,9 @@ fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
}
ast.CallExpr {
p.check_undefined_variables(exprs, val.left) ?
for arg in val.args {
p.check_undefined_variables(exprs, arg.expr) ?
}
}
ast.InfixExpr {
p.check_undefined_variables(exprs, val.left) ?