diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_e.out b/vlib/v/checker/tests/assign_expr_undefined_err_e.out new file mode 100644 index 0000000000..185abb3be8 --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_e.out @@ -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 | } diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_e.vv b/vlib/v/checker/tests/assign_expr_undefined_err_e.vv new file mode 100644 index 0000000000..47e4ed5f6a --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_e.vv @@ -0,0 +1,4 @@ +fn main() { + a, b := -a, -b + println(s) +} diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_f.out b/vlib/v/checker/tests/assign_expr_undefined_err_f.out new file mode 100644 index 0000000000..62f7ed3c89 --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_f.out @@ -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 | } diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_f.vv b/vlib/v/checker/tests/assign_expr_undefined_err_f.vv new file mode 100644 index 0000000000..79ec34862c --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_f.vv @@ -0,0 +1,4 @@ +fn main() { + a, b := (-a + 1), 1 + println('$a, $b') +} diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index 733af7cf9c..6917b819a3 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -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_)