cgen: remove .replace('T', ...)
parent
ec3b96924f
commit
023cddb160
|
@ -63,7 +63,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
|
|||
// foo<T>() => foo_int(), foo_string() etc
|
||||
gen_name := g.typ(g.cur_generic_type)
|
||||
name += '_' + gen_name
|
||||
type_name = type_name.replace('T', gen_name)
|
||||
}
|
||||
// if g.pref.show_cc && it.is_builtin {
|
||||
// println(name)
|
||||
|
@ -223,8 +222,6 @@ fn (mut g Gen) fn_args(args []table.Param, is_variadic bool) ([]string, []string
|
|||
// }
|
||||
if g.cur_generic_type != 0 {
|
||||
// foo<T>() => foo_int(), foo_string() etc
|
||||
gen_name := g.typ(g.cur_generic_type)
|
||||
arg_type_name = arg_type_name.replace('T', gen_name)
|
||||
}
|
||||
is_varg := i == args.len - 1 && is_variadic
|
||||
if is_varg {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
struct BuildData { x int }
|
||||
struct Tensor { x int }
|
||||
fn new_tensor<T>(data BuildData) Tensor {
|
||||
println('data: $data')
|
||||
x := T(data.x)
|
||||
println(x)
|
||||
return Tensor{ data.x }
|
||||
}
|
||||
fn test_generic_function_returning_type_starting_with_t() {
|
||||
ft := new_tensor<f64>(x:123)
|
||||
println(ft)
|
||||
assert typeof(ft) == 'Tensor'
|
||||
assert '$ft' == 'Tensor{\n x: 123\n}'
|
||||
//
|
||||
it := new_tensor<int>(x:456)
|
||||
println(it)
|
||||
assert typeof(it) == 'Tensor'
|
||||
assert '$it' == 'Tensor{\n x: 456\n}'
|
||||
}
|
||||
|
||||
// the following verifies that returning a generic type T
|
||||
// works at the same time as returning a type starting with T
|
||||
fn new_t<T>(o T) T {
|
||||
x := T(o)
|
||||
return x
|
||||
}
|
||||
fn test_generic_function_returning_t_type() {
|
||||
f := new_t<f64>(1.23)
|
||||
i := new_t<int>(456)
|
||||
assert '$f' == '1.23'
|
||||
assert '$i' == '456'
|
||||
}
|
Loading…
Reference in New Issue