cgen: fix thread return type generation (fix #20836) (#20850)

This commit is contained in:
Felipe Pena 2024-02-17 06:36:40 -03:00 committed by GitHub
parent fb675534b0
commit 298a2a2d7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View File

@ -122,9 +122,8 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
gohandle_name = '__v_thread'
}
} else {
opt := if is_opt { '${option_name}_' } else { '' }
res := if is_res { '${result_name}_' } else { '' }
gohandle_name = '__v_thread_${opt}${res}${g.table.sym(g.unwrap_generic(node.call_expr.return_type)).cname}'
ret_styp := g.typ(g.unwrap_generic(node.call_expr.return_type)).replace('*', '_ptr')
gohandle_name = '__v_thread_${ret_styp}'
}
if is_spawn {
if g.pref.os == .windows {

View File

@ -0,0 +1,21 @@
fn test_main() {
foo := spawn get_pointer()
ret := foo.wait()
assert *ret == 42
}
fn test_opt() {
foo := spawn get_pointer_opt()
ret := foo.wait()
assert *ret? == 42
}
fn get_pointer() &int {
val := 42
return &val
}
fn get_pointer_opt() ?&int {
val := 42
return &val
}