Skip to content

Commit

Permalink
cgen: fix thread return type generation (fix #20836) (#20850)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Feb 17, 2024
1 parent fb67553 commit 298a2a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions vlib/v/gen/c/spawn_and_go.v
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions vlib/v/tests/thread_ptr_ret_test.v
@@ -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
}

0 comments on commit 298a2a2

Please sign in to comment.