Skip to content

Commit

Permalink
cgen: fix code generation for generic channels (#19993)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Nov 26, 2023
1 parent e2aa9b3 commit bc62c5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vlib/v/ast/table.v
Expand Up @@ -922,7 +922,12 @@ pub fn (t &Table) chan_cname(elem_type Type, is_mut bool) string {
} else if elem_type.is_ptr() {
suffix = '_ptr'
}
return 'chan_${elem_type_sym.cname}' + suffix
type_name := if elem_type_sym.cname.contains('[') {
elem_type_sym.cname.replace_each(ast.map_cname_escape_seq)
} else {
elem_type_sym.cname
}
return 'chan_${type_name}' + suffix
}

@[inline]
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/chan_generic_test.v
@@ -0,0 +1,16 @@
struct Task[T] {
idx int
task T
}

fn check[T](input T) T {
ch := chan Task[T]{}
// do something with channel
ch.close()
return input
}

fn test_main() {
out := check[int](5)
assert out == 5
}

0 comments on commit bc62c5c

Please sign in to comment.