mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check undefined variable in if guard (#16138)
This commit is contained in:
parent
b40f1828b2
commit
ab78d5a7ba
@ -1,4 +1,4 @@
|
||||
vlib/v/checker/tests/undefined_ident_in_if_guard_err.vv:6:11: error: undefined variable: `re`
|
||||
vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.vv:6:11: error: undefined variable: `re`
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | if re := re.regex_opt('a') {
|
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.vv:3:17: error: undefined variable: `id`
|
||||
1 | fn main(){
|
||||
2 | items := {'a': 'A'}
|
||||
3 | if id := items[id] {} else {}
|
||||
| ~~
|
||||
4 | }
|
@ -0,0 +1,4 @@
|
||||
fn main(){
|
||||
items := {'a': 'A'}
|
||||
if id := items[id] {} else {}
|
||||
}
|
@ -59,6 +59,10 @@ fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
|
||||
p.check_undefined_variables(exprs, arg.expr)?
|
||||
}
|
||||
}
|
||||
ast.IndexExpr {
|
||||
p.check_undefined_variables(exprs, val.left)?
|
||||
p.check_undefined_variables(exprs, val.index)?
|
||||
}
|
||||
ast.InfixExpr {
|
||||
p.check_undefined_variables(exprs, val.left)?
|
||||
p.check_undefined_variables(exprs, val.right)?
|
||||
@ -155,6 +159,10 @@ fn (mut p Parser) check_undefined_variables_by_names(names []string, val ast.Exp
|
||||
p.check_undefined_variables_by_names(names, arg.expr)?
|
||||
}
|
||||
}
|
||||
ast.IndexExpr {
|
||||
p.check_undefined_variables_by_names(names, val.left)?
|
||||
p.check_undefined_variables_by_names(names, val.index)?
|
||||
}
|
||||
ast.InfixExpr {
|
||||
p.check_undefined_variables_by_names(names, val.left)?
|
||||
p.check_undefined_variables_by_names(names, val.right)?
|
||||
|
Loading…
Reference in New Issue
Block a user