cgen: fix codegen for `for k,v in map_of_pointers {`
parent
045579fd8a
commit
3fab0a5d05
|
@ -1221,6 +1221,9 @@ pub fn (mut t Table) complete_interface_check() {
|
|||
if idecl.fields.len > info.fields.len {
|
||||
continue
|
||||
}
|
||||
if idecl.typ == 0 {
|
||||
continue
|
||||
}
|
||||
// empty interface only generate type cast functions of the current module
|
||||
if idecl.methods.len == 0 && idecl.fields.len == 0
|
||||
&& tsym.mod != t.get_type_symbol(idecl.typ).mod {
|
||||
|
|
|
@ -2120,10 +2120,14 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
|
|||
} else {
|
||||
val_styp := g.typ(node.val_type)
|
||||
if node.val_type.is_ptr() {
|
||||
if node.val_is_mut {
|
||||
g.write('$val_styp ${c_name(node.val_var)} = &(*($val_styp)')
|
||||
} else {
|
||||
g.write('$val_styp ${c_name(node.val_var)} = (*($val_styp*)')
|
||||
}
|
||||
} else {
|
||||
g.write('$val_styp ${c_name(node.val_var)} = (*($val_styp*)')
|
||||
}
|
||||
g.writeln('DenseArray_value(&$cond_var${arw_or_pt}key_values, $idx));')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
fn test_for_in_map_of_pointers() {
|
||||
i := 123456
|
||||
pi := &i
|
||||
println('pi: $pi')
|
||||
mut my_map := map[int]&int{}
|
||||
my_map[0] = pi
|
||||
for k, wrong_value in my_map {
|
||||
good_value := my_map[k]
|
||||
println('k: $k \n wrong_value: $wrong_value \n good_value: $good_value')
|
||||
up_good_value := voidptr(good_value).hex_full()
|
||||
up_wrong_value := voidptr(wrong_value).hex_full()
|
||||
assert up_good_value == up_wrong_value
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue