1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: check undefined variable in if guard (#15882)

This commit is contained in:
yuyi 2022-09-26 15:17:39 +08:00 committed by GitHub
parent 8623186d31
commit 959eeaf1f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -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_)?

View File

@ -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 | }

View File

@ -0,0 +1,6 @@
module main
fn main() {
if f := f.g.x() {
}
}