1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: only cast as ast.Var if not unresolved, fixes #13561 (#13562)

This commit is contained in:
Larpon 2022-02-22 14:23:15 +01:00 committed by GitHub
parent 33d379d530
commit 1032cf5c04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

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

View File

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

View File

@ -0,0 +1,5 @@
fn main() {
for index, mut value in s.statements {
println('Hello $index $value')
}
}