diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 987ca3fe90..7d50b153dc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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 and get_string + // `foo()` => `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 diff --git a/vlib/v/tests/go_call_generic_fn_test.v b/vlib/v/tests/go_call_generic_fn_test.v new file mode 100644 index 0000000000..a42c2a73b3 --- /dev/null +++ b/vlib/v/tests/go_call_generic_fn_test.v @@ -0,0 +1,14 @@ +fn test(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(c, 'abcd') + x := <-c + assert x == 123 + println('bye') +}