gen: fix go call with generic function (#8093)
parent
a1245de25b
commit
2030875c0a
|
@ -5386,6 +5386,12 @@ fn (mut g Gen) go_stmt(node ast.GoStmt) {
|
|||
tmp := g.new_tmp_var()
|
||||
expr := node.call_expr as ast.CallExpr
|
||||
mut name := expr.name // util.no_dots(expr.name)
|
||||
// TODO: fn call is duplicated. merge with fn_call().
|
||||
if expr.generic_type != table.void_type && expr.generic_type != 0 {
|
||||
// Using _T_ to differentiate between get<string> and get_string
|
||||
// `foo<int>()` => `foo_T_int()`
|
||||
name += '_T_' + g.typ(expr.generic_type)
|
||||
}
|
||||
if expr.is_method {
|
||||
receiver_sym := g.table.get_type_symbol(expr.receiver_type)
|
||||
name = receiver_sym.name + '_' + name
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
fn test<T>(c chan int, s T) {
|
||||
println('hi from generic fn test, T: ' + typeof(s).name)
|
||||
println('s: $s')
|
||||
assert true
|
||||
c <- 123
|
||||
}
|
||||
|
||||
fn test_go_generic_fn() {
|
||||
mut c := chan int{}
|
||||
go test<string>(c, 'abcd')
|
||||
x := <-c
|
||||
assert x == 123
|
||||
println('bye')
|
||||
}
|
Loading…
Reference in New Issue