Skip to content

Commit 1032cf5

Browse files
authored
checker: only cast as ast.Var if not unresolved, fixes #13561 (#13562)
1 parent 33d379d commit 1032cf5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

vlib/v/checker/for.v

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
119119
}
120120
ast.SelectorExpr {
121121
root_ident := node.cond.root_ident() or { node.cond.expr as ast.Ident }
122-
if !(root_ident.obj as ast.Var).is_mut {
123-
c.error('field `$node.cond.field_name` is immutable, it cannot be changed',
124-
node.cond.pos)
122+
if root_ident.kind != .unresolved {
123+
if !(root_ident.obj as ast.Var).is_mut {
124+
c.error('field `$node.cond.field_name` is immutable, it cannot be changed',
125+
node.cond.pos)
126+
}
125127
}
126128
}
127129
else {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
vlib/v/checker/tests/for_in_invalid_identifier.vv:2:26: error: undefined ident: `s`
2+
1 | fn main() {
3+
2 | for index, mut value in s.statements {
4+
| ^
5+
3 | println('Hello $index $value')
6+
4 | }
7+
vlib/v/checker/tests/for_in_invalid_identifier.vv:3:26: error: no known default format for type `void`
8+
1 | fn main() {
9+
2 | for index, mut value in s.statements {
10+
3 | println('Hello $index $value')
11+
| ~~~~~
12+
4 | }
13+
5 | }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
for index, mut value in s.statements {
3+
println('Hello $index $value')
4+
}
5+
}

0 commit comments

Comments
 (0)