mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a0a1807e2b
commit
6438512529
@ -2590,6 +2590,8 @@ 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 == .map && !(node.key_var.len > 0 && node.val_var.len > 0) {
|
||||
c.error(
|
||||
|
14
vlib/v/checker/tests/for_in_mut_string.out
Normal file
14
vlib/v/checker/tests/for_in_mut_string.out
Normal file
@ -0,0 +1,14 @@
|
||||
vlib/v/checker/tests/for_in_mut_string.vv:19:6: error: string type is immutable, it cannot be changed
|
||||
17 |
|
||||
18 | fn wrap_text(mut gv Grid) {
|
||||
19 | for mut ch in gv.header {
|
||||
| ~~~
|
||||
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)
|
||||
| ~~~~~~~~~~~
|
||||
21 | }
|
||||
22 | }
|
22
vlib/v/checker/tests/for_in_mut_string.vv
Normal file
22
vlib/v/checker/tests/for_in_mut_string.vv
Normal file
@ -0,0 +1,22 @@
|
||||
module main
|
||||
|
||||
[heap]
|
||||
pub struct Grid {
|
||||
pub mut:
|
||||
header string
|
||||
}
|
||||
|
||||
fn main() {
|
||||
h := 'yo'
|
||||
|
||||
mut grid := Grid{
|
||||
header: h
|
||||
}
|
||||
wrap_text(mut grid)
|
||||
}
|
||||
|
||||
fn wrap_text(mut gv Grid) {
|
||||
for mut ch in gv.header {
|
||||
println(ch)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user