diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_a.out b/vlib/v/checker/tests/assign_expr_undefined_err_a.out new file mode 100644 index 0000000000..e3525785ca --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_a.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/assign_expr_undefined_err_a.v:2:7: error: undefined: `a` + 1 | fn main() { + 2 | a := a + | ^ + 3 | println(a) + 4 | } diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.vv b/vlib/v/checker/tests/assign_expr_undefined_err_a.vv similarity index 94% rename from vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.vv rename to vlib/v/checker/tests/assign_expr_undefined_err_a.vv index 26ff9bb04a..05ffdf416e 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.vv +++ b/vlib/v/checker/tests/assign_expr_undefined_err_a.vv @@ -1,4 +1,4 @@ fn main() { a := a println(a) -} \ No newline at end of file +} diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.out b/vlib/v/checker/tests/assign_expr_undefined_err_b.out similarity index 51% rename from vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.out rename to vlib/v/checker/tests/assign_expr_undefined_err_b.out index 35c836f7db..9d320e7292 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.out +++ b/vlib/v/checker/tests/assign_expr_undefined_err_b.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.v:2:10: error: unresolved variables `a` +vlib/v/checker/tests/assign_expr_undefined_err_b.v:2:10: error: undefined: `a` 1 | fn main() { 2 | a, b := a, b | ^ diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.vv b/vlib/v/checker/tests/assign_expr_undefined_err_b.vv similarity index 95% rename from vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.vv rename to vlib/v/checker/tests/assign_expr_undefined_err_b.vv index 8e9d236549..b77ab6cbd9 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_b.vv +++ b/vlib/v/checker/tests/assign_expr_undefined_err_b.vv @@ -1,4 +1,4 @@ fn main() { a, b := a, b println('$a, $b') -} \ No newline at end of file +} diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.out b/vlib/v/checker/tests/assign_expr_undefined_err_c.out similarity index 53% rename from vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.out rename to vlib/v/checker/tests/assign_expr_undefined_err_c.out index 3126e45e1a..47227f236f 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.out +++ b/vlib/v/checker/tests/assign_expr_undefined_err_c.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.v:2:10: error: unresolved variables `a` +vlib/v/checker/tests/assign_expr_undefined_err_c.v:2:10: error: undefined: `a` 1 | fn main() { 2 | a, b := a + 1, b * 3 | ^ diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.vv b/vlib/v/checker/tests/assign_expr_undefined_err_c.vv similarity index 96% rename from vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.vv rename to vlib/v/checker/tests/assign_expr_undefined_err_c.vv index de3950acb7..b845893201 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_c.vv +++ b/vlib/v/checker/tests/assign_expr_undefined_err_c.vv @@ -1,4 +1,4 @@ fn main() { a, b := a + 1, b * 3 println('$a, $b') -} \ No newline at end of file +} diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_d.out b/vlib/v/checker/tests/assign_expr_undefined_err_d.out new file mode 100644 index 0000000000..79f1fa69c8 --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_d.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/assign_expr_undefined_err_d.v:2:9: error: undefined: `s` + 1 | fn main() { + 2 | s := '$s' + | ^ + 3 | println(s) + 4 | } diff --git a/vlib/v/checker/tests/assign_expr_undefined_err_d.vv b/vlib/v/checker/tests/assign_expr_undefined_err_d.vv new file mode 100644 index 0000000000..f9acc47b3f --- /dev/null +++ b/vlib/v/checker/tests/assign_expr_undefined_err_d.vv @@ -0,0 +1,4 @@ +fn main() { + s := '$s' + println(s) +} diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.out b/vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.out deleted file mode 100644 index 7daf00ca9c..0000000000 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.out +++ /dev/null @@ -1,6 +0,0 @@ -vlib/v/checker/tests/assign_expr_unresolved_variables_err_a.v:2:7: error: unresolved variables `a` - 1 | fn main() { - 2 | a := a - | ^ - 3 | println(a) - 4 | } diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index afc81badf0..265190900b 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -9,18 +9,23 @@ fn (mut p Parser) assign_stmt() ast.Stmt { return p.partial_assign_stmt([]) } -fn (mut p Parser) check_unresolved_variables(idents []ast.Ident, expr ast.Expr) { +fn (mut p Parser) check_undefined_variables(idents []ast.Ident, expr ast.Expr) { match expr { ast.Ident { for ident in idents { if ident.name == it.name { - p.error_with_pos('unresolved variables `$it.name`', it.pos) + p.error_with_pos('undefined: `$it.name`', it.pos) } } } ast.InfixExpr { - p.check_unresolved_variables(idents, it.left) - p.check_unresolved_variables(idents, it.right) + p.check_undefined_variables(idents, it.left) + p.check_undefined_variables(idents, it.right) + } + ast.StringInterLiteral { + for expr_ in it.exprs { + p.check_undefined_variables(idents, expr_) + } } else {} } @@ -44,7 +49,7 @@ fn (mut p Parser) partial_assign_stmt(known_lhs []ast.Ident) ast.Stmt { if is_decl { // a, b := a + 1, b for expr in exprs { - p.check_unresolved_variables(idents, expr) + p.check_undefined_variables(idents, expr) } } for i, ident in idents {