mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow for mut letter in 'abc' {
(#17234)
This commit is contained in:
parent
858ce4e35d
commit
242d6fa1ff
@ -113,6 +113,9 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
||||
}
|
||||
else {}
|
||||
}
|
||||
} else if node.val_is_mut {
|
||||
c.error('string type is immutable, it cannot be changed', node.pos)
|
||||
return
|
||||
}
|
||||
if sym.kind == .struct_ {
|
||||
// iterators
|
||||
@ -139,8 +142,6 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
||||
node.kind = sym.kind
|
||||
node.val_type = val_type
|
||||
node.scope.update_var_type(node.val_var, val_type)
|
||||
} else if sym.kind == .string && node.val_is_mut {
|
||||
c.error('string type is immutable, it cannot be changed', node.pos)
|
||||
} else if sym.kind == .any {
|
||||
node.cond_type = typ
|
||||
node.kind = sym.kind
|
||||
|
@ -5,10 +5,10 @@ vlib/v/checker/tests/for_in_mut_string.vv:19:6: error: string type is immutable,
|
||||
| ~~~
|
||||
20 | println(ch)
|
||||
21 | }
|
||||
vlib/v/checker/tests/for_in_mut_string.vv:20:3: error: `println` can not print void expressions
|
||||
18 | fn wrap_text(mut gv Grid) {
|
||||
19 | for mut ch in gv.header {
|
||||
20 | println(ch)
|
||||
| ~~~~~~~~~~~
|
||||
vlib/v/checker/tests/for_in_mut_string.vv:23:6: error: string type is immutable, it cannot be changed
|
||||
21 | }
|
||||
22 | }
|
||||
22 |
|
||||
23 | for mut letter in 'abc' {
|
||||
| ~~~
|
||||
24 | bit := letter - 1
|
||||
25 | println(bit)
|
||||
|
@ -19,4 +19,9 @@ fn wrap_text(mut gv Grid) {
|
||||
for mut ch in gv.header {
|
||||
println(ch)
|
||||
}
|
||||
|
||||
for mut letter in 'abc' {
|
||||
bit := letter - 1
|
||||
println(bit)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user