parser: fix self-referenced error
parent
3aeaa24df6
commit
30ca08aaa3
|
@ -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 | }
|
|
@ -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
|
||||
| ^
|
|
@ -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
|
||||
| ^
|
|
@ -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 | }
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
s := '$s'
|
||||
println(s)
|
||||
}
|
|
@ -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 | }
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue