diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index bc1ddda20f..45eebdf147 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -200,6 +200,9 @@ fn (mut p Parser) check_undefined_variables_by_names(names []string, val ast.Exp ast.PrefixExpr { p.check_undefined_variables_by_names(names, val.right)? } + ast.SelectorExpr { + p.check_undefined_variables_by_names(names, val.expr)? + } ast.StringInterLiteral { for expr_ in val.exprs { p.check_undefined_variables_by_names(names, expr_)? diff --git a/vlib/v/parser/tests/if_guard_undefined_variable_err.out b/vlib/v/parser/tests/if_guard_undefined_variable_err.out new file mode 100644 index 0000000000..31b2cfbdc7 --- /dev/null +++ b/vlib/v/parser/tests/if_guard_undefined_variable_err.out @@ -0,0 +1,7 @@ +vlib/v/parser/tests/if_guard_undefined_variable_err.vv:4:10: error: undefined variable: `f` + 2 | + 3 | fn main() { + 4 | if f := f.g.x() { + | ^ + 5 | } + 6 | } diff --git a/vlib/v/parser/tests/if_guard_undefined_variable_err.vv b/vlib/v/parser/tests/if_guard_undefined_variable_err.vv new file mode 100644 index 0000000000..b934049c47 --- /dev/null +++ b/vlib/v/parser/tests/if_guard_undefined_variable_err.vv @@ -0,0 +1,6 @@ +module main + +fn main() { + if f := f.g.x() { + } +}