Skip to content

Commit

Permalink
cgen: fix spawn generic codegen (fix #22484) (#22491)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Oct 11, 2024
1 parent 5aa6eaf commit 0cf3a44
Show file tree
Hide file tree
Showing 2 changed files with 34 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 @@ -248,12 +248,12 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
}
} else {
if f := g.table.find_fn(node.call_expr.name) {
mut muttable := unsafe { &ast.Table(g.table) }
return_type := muttable.convert_generic_type(f.return_type, f.generic_names,
node.call_expr.concrete_types) or { f.return_type }
concrete_types := node.call_expr.concrete_types.map(g.unwrap_generic(it))
return_type := g.table.convert_generic_type(f.return_type, f.generic_names,
concrete_types) or { f.return_type }
mut arg_types := f.params.map(it.typ)
arg_types = arg_types.map(muttable.convert_generic_type(it, f.generic_names,
node.call_expr.concrete_types) or { it })
arg_types = arg_types.map(g.table.convert_generic_type(it, f.generic_names,
concrete_types) or { it })
for i, typ in arg_types {
mut typ_sym := g.table.sym(typ)
for {
Expand Down
29 changes: 29 additions & 0 deletions vlib/v/tests/generics/generic_spawn_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module main

struct In[T] {
source chan T
}

fn emit[T](s In[T], ar []T) {
for _, i in ar {
s.source <- i
}
}

fn from[T](ar []T) In[T] {
s := In[T]{}

spawn emit(s, ar)

return s
}

fn (i In[T]) get() T {
return <-i.source
}

fn test_main() {
v := from[int]([1]).get()

assert v == 1
}

0 comments on commit 0cf3a44

Please sign in to comment.