parent
5b041db442
commit
5f9af3f594
|
@ -1385,6 +1385,10 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
|
|||
g.write('\t')
|
||||
g.write_fn_ptr_decl(val_sym.info as table.FnType, c_name(node.val_var))
|
||||
g.writeln(' = ((voidptr*)$tmp${op_field}data)[$i];')
|
||||
} else if val_sym.kind == .array_fixed && !node.val_is_mut {
|
||||
right := '(($styp*)$tmp${op_field}data)[$i]'
|
||||
g.writeln('\t$styp ${c_name(node.val_var)};')
|
||||
g.writeln('\tmemcpy(*($styp*)${c_name(node.val_var)}, (byte*)$right, sizeof($styp));')
|
||||
} else {
|
||||
// If val is mutable (pointer behind the scenes), we need to generate
|
||||
// `int* val = ((int*)arr.data) + i;`
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
fn test_for_in_containers_of_fixed_array() {
|
||||
mut rets := []string{}
|
||||
arr := [][2]int{len: 3}
|
||||
|
||||
for pair in arr {
|
||||
println(pair)
|
||||
rets << '$pair'
|
||||
}
|
||||
assert rets[0] == '[0, 0]'
|
||||
assert rets[1] == '[0, 0]'
|
||||
assert rets[2] == '[0, 0]'
|
||||
}
|
||||
|
||||
fn test_for_mut_in_containers_of_fixed_array() {
|
||||
mut rets := []string{}
|
||||
mut arr := [][2]int{len: 3}
|
||||
|
||||
for mut pair in arr {
|
||||
println(pair)
|
||||
rets << '$pair'
|
||||
}
|
||||
assert rets[0] == '[0, 0]'
|
||||
assert rets[1] == '[0, 0]'
|
||||
assert rets[2] == '[0, 0]'
|
||||
}
|
Loading…
Reference in New Issue