Skip to content

Commit

Permalink
cgen: fix gowrapper codegen for receiver ptrptr (fix #23798) (#23800)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Feb 24, 2025
1 parent 9921692 commit 0f58a02
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vlib/v/gen/c/spawn_and_go.v
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
}
if expr.is_method {
g.write('${arg_tmp_var}${dot}arg0 = ')
if expr.left is ast.Ident && expr.left.obj.typ.is_ptr()
if mut expr.left is ast.Ident && expr.left.obj.typ.is_ptr()
&& !node.call_expr.receiver_type.is_ptr() {
g.write('*')
g.write('*'.repeat(expr.left.obj.typ.nr_muls()))
}
g.expr(expr.left)
g.writeln(';')
Expand Down Expand Up @@ -271,10 +271,10 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
receiver_type_name := util.no_dots(rec_cc_type)
g.gowrappers.write_string2('${c_name(receiver_type_name)}_name_table[',
'arg->arg0')
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
dot_or_ptr := g.dot_or_ptr(unwrapped_rec_type)
mname := c_name(expr.name)
g.gowrappers.write_string2('${idot}_typ]._method_${mname}(', 'arg->arg0')
g.gowrappers.write_string('${idot}_object')
g.gowrappers.write_string2('${dot_or_ptr}_typ]._method_${mname}(', 'arg->arg0')
g.gowrappers.write_string('${dot_or_ptr}_object')
} else if typ_sym.kind == .struct && expr.is_field {
g.gowrappers.write_string('arg->arg0')
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
Expand Down
37 changes: 37 additions & 0 deletions vlib/v/tests/concurrency/mut_receiver_gowrapper_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module main

@[heap]
interface IGameObject {
mut:
name string
parent ?&IGameObject
children []&IGameObject
advance()
}

@[heap]
struct GameObject implements IGameObject {
mut:
name string
parent ?&IGameObject
children []&IGameObject
}

struct Ship implements IGameObject {
GameObject
speed f32
}

fn (mut gameobject GameObject) advance() {
for mut child in gameobject.children {
go child.advance()
}
}

fn test_main() {
mut ship := &Ship{
name: 'ship'
}
ship.advance()
assert true
}

0 comments on commit 0f58a02

Please sign in to comment.