diff --git a/vlib/v/checker/tests/undefined_ident_in_if_guard_err.out b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.out similarity index 59% rename from vlib/v/checker/tests/undefined_ident_in_if_guard_err.out rename to vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.out index 23584a5012..d9ebc58e52 100644 --- a/vlib/v/checker/tests/undefined_ident_in_if_guard_err.out +++ b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.out @@ -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') { diff --git a/vlib/v/checker/tests/undefined_ident_in_if_guard_err.vv b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.vv similarity index 100% rename from vlib/v/checker/tests/undefined_ident_in_if_guard_err.vv rename to vlib/v/checker/tests/undefined_ident_in_if_guard_err_a.vv diff --git a/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.out b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.out new file mode 100644 index 0000000000..a6d6e0f0ea --- /dev/null +++ b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.out @@ -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 | } diff --git a/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.vv b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.vv new file mode 100644 index 0000000000..7c344dc5f7 --- /dev/null +++ b/vlib/v/checker/tests/undefined_ident_in_if_guard_err_b.vv @@ -0,0 +1,4 @@ +fn main(){ + items := {'a': 'A'} + if id := items[id] {} else {} +} diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index 52e6004c2e..9bb2594c7b 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -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)?