Skip to content

Commit 0f58a02

Browse files
authored
cgen: fix gowrapper codegen for receiver ptrptr (fix #23798) (#23800)
1 parent 9921692 commit 0f58a02

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

vlib/v/gen/c/spawn_and_go.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
106106
}
107107
if expr.is_method {
108108
g.write('${arg_tmp_var}${dot}arg0 = ')
109-
if expr.left is ast.Ident && expr.left.obj.typ.is_ptr()
109+
if mut expr.left is ast.Ident && expr.left.obj.typ.is_ptr()
110110
&& !node.call_expr.receiver_type.is_ptr() {
111-
g.write('*')
111+
g.write('*'.repeat(expr.left.obj.typ.nr_muls()))
112112
}
113113
g.expr(expr.left)
114114
g.writeln(';')
@@ -271,10 +271,10 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
271271
receiver_type_name := util.no_dots(rec_cc_type)
272272
g.gowrappers.write_string2('${c_name(receiver_type_name)}_name_table[',
273273
'arg->arg0')
274-
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
274+
dot_or_ptr := g.dot_or_ptr(unwrapped_rec_type)
275275
mname := c_name(expr.name)
276-
g.gowrappers.write_string2('${idot}_typ]._method_${mname}(', 'arg->arg0')
277-
g.gowrappers.write_string('${idot}_object')
276+
g.gowrappers.write_string2('${dot_or_ptr}_typ]._method_${mname}(', 'arg->arg0')
277+
g.gowrappers.write_string('${dot_or_ptr}_object')
278278
} else if typ_sym.kind == .struct && expr.is_field {
279279
g.gowrappers.write_string('arg->arg0')
280280
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module main
2+
3+
@[heap]
4+
interface IGameObject {
5+
mut:
6+
name string
7+
parent ?&IGameObject
8+
children []&IGameObject
9+
advance()
10+
}
11+
12+
@[heap]
13+
struct GameObject implements IGameObject {
14+
mut:
15+
name string
16+
parent ?&IGameObject
17+
children []&IGameObject
18+
}
19+
20+
struct Ship implements IGameObject {
21+
GameObject
22+
speed f32
23+
}
24+
25+
fn (mut gameobject GameObject) advance() {
26+
for mut child in gameobject.children {
27+
go child.advance()
28+
}
29+
}
30+
31+
fn test_main() {
32+
mut ship := &Ship{
33+
name: 'ship'
34+
}
35+
ship.advance()
36+
assert true
37+
}

0 commit comments

Comments
 (0)