Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cgen: fix gowrapper codegen for receiver ptrptr #23800

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading