parser: check assign expr with undefined variables of struct_init (#13495)
parent
89b99ad4c3
commit
842fd7a27e
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/assign_expr_undefined_err_l.vv:29:6: error: undefined variable: `poo`
|
||||
27 | poo := Stru{
|
||||
28 | a: 123
|
||||
29 | i: poo.result()
|
||||
| ~~~
|
||||
30 | }
|
||||
31 | println('$poo')
|
|
@ -0,0 +1,32 @@
|
|||
module main
|
||||
|
||||
struct Stru {
|
||||
mut:
|
||||
a int
|
||||
i Iface2
|
||||
}
|
||||
|
||||
interface Iface {
|
||||
result() &Iface2
|
||||
}
|
||||
|
||||
interface Iface2 {
|
||||
result2() Iface
|
||||
}
|
||||
|
||||
pub fn (s Stru)result() &Iface2 {
|
||||
return &Stru{}
|
||||
}
|
||||
|
||||
pub fn (s Stru)result2() Iface {
|
||||
return &Stru{}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println('hello world')
|
||||
poo := Stru{
|
||||
a: 123
|
||||
i: poo.result()
|
||||
}
|
||||
println('$poo')
|
||||
}
|
|
@ -18,7 +18,7 @@ fn (mut p Parser) assign_stmt() ast.Stmt {
|
|||
return p.partial_assign_stmt(exprs, comments)
|
||||
}
|
||||
|
||||
const max_expr_level = 310
|
||||
const max_expr_level = 100
|
||||
|
||||
fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
|
||||
p.expr_level++
|
||||
|
@ -85,6 +85,12 @@ fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
|
|||
p.check_undefined_variables(exprs, expr_) ?
|
||||
}
|
||||
}
|
||||
ast.StructInit {
|
||||
fields := val.fields.clone()
|
||||
for field in fields {
|
||||
p.check_undefined_variables(exprs, field.expr) ?
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue