mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix spawn call fn struct field(fix #18862)
This commit is contained in:
parent
65a493d023
commit
d7d38926e2
@ -91,7 +91,8 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
|
||||
} else {
|
||||
name
|
||||
}
|
||||
if !(expr.is_method && g.table.sym(expr.receiver_type).kind == .interface_) {
|
||||
if !(expr.is_method && (g.table.sym(expr.receiver_type).kind == .interface_
|
||||
|| (g.table.sym(expr.receiver_type).kind == .struct_ && expr.is_field))) {
|
||||
g.writeln('${arg_tmp_var}${dot}fn = ${fn_name};')
|
||||
}
|
||||
if expr.is_method {
|
||||
@ -250,7 +251,9 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
|
||||
}
|
||||
}
|
||||
}
|
||||
g.type_definitions.writeln('\t${fn_var};')
|
||||
if fn_var != '' {
|
||||
g.type_definitions.writeln('\t${fn_var};')
|
||||
}
|
||||
if expr.is_method {
|
||||
styp := g.typ(expr.receiver_type)
|
||||
g.type_definitions.writeln('\t${styp} arg0;')
|
||||
@ -298,11 +301,16 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
|
||||
g.gowrappers.write_string('${idot}_typ]._method_${mname}(')
|
||||
g.gowrappers.write_string('arg->arg0')
|
||||
g.gowrappers.write_string('${idot}_object')
|
||||
} else if typ_sym.kind == .struct_ && expr.is_field {
|
||||
g.gowrappers.write_string('arg->arg0')
|
||||
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
|
||||
mname := c_name(expr.name)
|
||||
g.gowrappers.write_string('${idot}${mname}(')
|
||||
} else {
|
||||
g.gowrappers.write_string('arg->fn(')
|
||||
g.gowrappers.write_string('arg->arg0')
|
||||
}
|
||||
if expr.args.len > 0 {
|
||||
if expr.args.len > 0 && (typ_sym.kind != .struct_ || !expr.is_field) {
|
||||
g.gowrappers.write_string(', ')
|
||||
}
|
||||
} else {
|
||||
|
2
vlib/v/gen/c/testdata/spawn_call_fn_struct_field.out
vendored
Normal file
2
vlib/v/gen/c/testdata/spawn_call_fn_struct_field.out
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
hello
|
||||
hello
|
18
vlib/v/gen/c/testdata/spawn_call_fn_struct_field.vv
vendored
Normal file
18
vlib/v/gen/c/testdata/spawn_call_fn_struct_field.vv
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
struct Foo {
|
||||
mut:
|
||||
func1 fn (int) = unsafe { nil }
|
||||
func2 fn (int) = do
|
||||
}
|
||||
|
||||
fn do(a int) {
|
||||
println('hello')
|
||||
}
|
||||
|
||||
mut foo := Foo{}
|
||||
|
||||
foo.func1 = do
|
||||
mut p := spawn foo.func1(1)
|
||||
p.wait()
|
||||
|
||||
p = spawn foo.func2(1)
|
||||
p.wait()
|
Loading…
Reference in New Issue
Block a user