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

parser: check undefined variable of assign_expr

This commit is contained in:
yuyi 2020-05-29 23:38:40 +08:00 committed by GitHub
parent f3c5f36317
commit 1e504fb388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/assign_expr_undefined_err_e.v:2:11: error: undefined variable: `a`
1 | fn main() {
2 | a, b := -a, -b
| ^
3 | println(s)
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
a, b := -a, -b
println(s)
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/assign_expr_undefined_err_f.v:2:12: error: undefined variable: `a`
1 | fn main() {
2 | a, b := (-a + 1), 1
| ^
3 | println('$a, $b')
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
a, b := (-a + 1), 1
println('$a, $b')
}

View File

@ -22,6 +22,15 @@ fn (mut p Parser) check_undefined_variables(idents []ast.Ident, expr ast.Expr) {
p.check_undefined_variables(idents, it.left)
p.check_undefined_variables(idents, it.right)
}
ast.ParExpr {
p.check_undefined_variables(idents, it.expr)
}
ast.PostfixExpr {
p.check_undefined_variables(idents, it.expr)
}
ast.PrefixExpr {
p.check_undefined_variables(idents, it.right)
}
ast.StringInterLiteral {
for expr_ in it.exprs {
p.check_undefined_variables(idents, expr_)