gen: fix go call with generic function (#8093)

pull/8026/head^2
Daniel Däschle 2021-01-13 16:35:50 +01:00 committed by GitHub
parent a1245de25b
commit 2030875c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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')
}