1
0
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:
Felipe Pena 2023-01-17 01:47:51 -03:00 committed by GitHub
parent 21807f94a2
commit f634c6e0a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

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

View File

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

View 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{})
}