mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix postfix var checking break (#16984)
This commit is contained in:
parent
21807f94a2
commit
f634c6e0a4
@ -3508,7 +3508,7 @@ fn (c &Checker) has_return(stmts []ast.Stmt) ?bool {
|
||||
|
||||
pub fn (mut c Checker) is_comptime_var(node ast.Expr) bool {
|
||||
return c.inside_comptime_for_field && node is ast.Ident
|
||||
&& (node as ast.Ident).info is ast.IdentVar && ((node as ast.Ident).obj as ast.Var).is_comptime_field
|
||||
&& (node as ast.Ident).info is ast.IdentVar && (node as ast.Ident).kind == .variable && ((node as ast.Ident).obj as ast.Var).is_comptime_field
|
||||
}
|
||||
|
||||
fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) ast.Type {
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/undefined_var_in_comptime_for_test.vv:11:3: error: undefined ident: `fields_len`
|
||||
9 | fn test[U](val U) {
|
||||
10 | $for field in U.fields {
|
||||
11 | fields_len++
|
||||
| ~~~~~~~~~~
|
||||
12 | println(field)
|
||||
13 | }
|
18
vlib/v/checker/tests/undefined_var_in_comptime_for_test.vv
Normal file
18
vlib/v/checker/tests/undefined_var_in_comptime_for_test.vv
Normal file
@ -0,0 +1,18 @@
|
||||
module main
|
||||
|
||||
struct Struct {
|
||||
b string
|
||||
a ?string
|
||||
c string
|
||||
}
|
||||
|
||||
fn test[U](val U) {
|
||||
$for field in U.fields {
|
||||
fields_len++
|
||||
println(field)
|
||||
}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
test(Struct{})
|
||||
}
|
Loading…
Reference in New Issue
Block a user