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 {
|
if idecl.fields.len > info.fields.len {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if idecl.typ == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// empty interface only generate type cast functions of the current module
|
// empty interface only generate type cast functions of the current module
|
||||||
if idecl.methods.len == 0 && idecl.fields.len == 0
|
if idecl.methods.len == 0 && idecl.fields.len == 0
|
||||||
&& tsym.mod != t.get_type_symbol(idecl.typ).mod {
|
&& tsym.mod != t.get_type_symbol(idecl.typ).mod {
|
||||||
|
|
|
@ -2120,7 +2120,11 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
|
||||||
} else {
|
} else {
|
||||||
val_styp := g.typ(node.val_type)
|
val_styp := g.typ(node.val_type)
|
||||||
if node.val_type.is_ptr() {
|
if node.val_type.is_ptr() {
|
||||||
g.write('$val_styp ${c_name(node.val_var)} = &(*($val_styp)')
|
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 {
|
} else {
|
||||||
g.write('$val_styp ${c_name(node.val_var)} = (*($val_styp*)')
|
g.write('$val_styp ${c_name(node.val_var)} = (*($val_styp*)')
|
||||||
}
|
}
|
||||||
|
|
|
@ -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