Skip to content

Commit 0cf3a44

Browse files
authored
cgen: fix spawn generic codegen (fix #22484) (#22491)
1 parent 5aa6eaf commit 0cf3a44

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

vlib/v/gen/c/spawn_and_go.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
248248
}
249249
} else {
250250
if f := g.table.find_fn(node.call_expr.name) {
251-
mut muttable := unsafe { &ast.Table(g.table) }
252-
return_type := muttable.convert_generic_type(f.return_type, f.generic_names,
253-
node.call_expr.concrete_types) or { f.return_type }
251+
concrete_types := node.call_expr.concrete_types.map(g.unwrap_generic(it))
252+
return_type := g.table.convert_generic_type(f.return_type, f.generic_names,
253+
concrete_types) or { f.return_type }
254254
mut arg_types := f.params.map(it.typ)
255-
arg_types = arg_types.map(muttable.convert_generic_type(it, f.generic_names,
256-
node.call_expr.concrete_types) or { it })
255+
arg_types = arg_types.map(g.table.convert_generic_type(it, f.generic_names,
256+
concrete_types) or { it })
257257
for i, typ in arg_types {
258258
mut typ_sym := g.table.sym(typ)
259259
for {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module main
2+
3+
struct In[T] {
4+
source chan T
5+
}
6+
7+
fn emit[T](s In[T], ar []T) {
8+
for _, i in ar {
9+
s.source <- i
10+
}
11+
}
12+
13+
fn from[T](ar []T) In[T] {
14+
s := In[T]{}
15+
16+
spawn emit(s, ar)
17+
18+
return s
19+
}
20+
21+
fn (i In[T]) get() T {
22+
return <-i.source
23+
}
24+
25+
fn test_main() {
26+
v := from[int]([1]).get()
27+
28+
assert v == 1
29+
}

0 commit comments

Comments
 (0)