mirror of
https://github.com/vlang/v.git
synced 2025-09-17 11:26:17 -04:00
cgen: fix code generation for generic channels (#19993)
This commit is contained in:
parent
e2aa9b358d
commit
bc62c5cfd7
@ -922,7 +922,12 @@ pub fn (t &Table) chan_cname(elem_type Type, is_mut bool) string {
|
|||||||
} else if elem_type.is_ptr() {
|
} else if elem_type.is_ptr() {
|
||||||
suffix = '_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]
|
@[inline]
|
||||||
|
16
vlib/v/tests/chan_generic_test.v
Normal file
16
vlib/v/tests/chan_generic_test.v
Normal file
@ -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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user