diff --git a/vlib/v/checker/for.v b/vlib/v/checker/for.v index 91860ca871..ce7280a417 100644 --- a/vlib/v/checker/for.v +++ b/vlib/v/checker/for.v @@ -119,9 +119,11 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) { } ast.SelectorExpr { root_ident := node.cond.root_ident() or { node.cond.expr as ast.Ident } - if !(root_ident.obj as ast.Var).is_mut { - c.error('field `$node.cond.field_name` is immutable, it cannot be changed', - node.cond.pos) + if root_ident.kind != .unresolved { + if !(root_ident.obj as ast.Var).is_mut { + c.error('field `$node.cond.field_name` is immutable, it cannot be changed', + node.cond.pos) + } } } else {} diff --git a/vlib/v/checker/tests/for_in_invalid_identifier.out b/vlib/v/checker/tests/for_in_invalid_identifier.out new file mode 100644 index 0000000000..79115d7d71 --- /dev/null +++ b/vlib/v/checker/tests/for_in_invalid_identifier.out @@ -0,0 +1,13 @@ +vlib/v/checker/tests/for_in_invalid_identifier.vv:2:26: error: undefined ident: `s` + 1 | fn main() { + 2 | for index, mut value in s.statements { + | ^ + 3 | println('Hello $index $value') + 4 | } +vlib/v/checker/tests/for_in_invalid_identifier.vv:3:26: error: no known default format for type `void` + 1 | fn main() { + 2 | for index, mut value in s.statements { + 3 | println('Hello $index $value') + | ~~~~~ + 4 | } + 5 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/for_in_invalid_identifier.vv b/vlib/v/checker/tests/for_in_invalid_identifier.vv new file mode 100644 index 0000000000..c062fed3d3 --- /dev/null +++ b/vlib/v/checker/tests/for_in_invalid_identifier.vv @@ -0,0 +1,5 @@ +fn main() { + for index, mut value in s.statements { + println('Hello $index $value') + } +}