mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
6e4dad9acf
commit
aadeb62bbf
@ -60,9 +60,10 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
|
||||
}
|
||||
mut type_name := g.typ(it.return_type)
|
||||
if g.cur_generic_type != 0 {
|
||||
// foo<T>() => foo_int(), foo_string() etc
|
||||
// foo<T>() => foo_T_int(), foo_T_string() etc
|
||||
gen_name := g.typ(g.cur_generic_type)
|
||||
name += '_' + gen_name
|
||||
// Using _T_ to differentiate between get<string> and get_string
|
||||
name += '_T_' + gen_name
|
||||
}
|
||||
// if g.pref.show_cc && it.is_builtin {
|
||||
// println(name)
|
||||
@ -534,8 +535,9 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||
name = c_name(name)
|
||||
}
|
||||
if node.generic_type != table.void_type && node.generic_type != 0 {
|
||||
// `foo<int>()` => `foo_int()`
|
||||
name += '_' + g.typ(node.generic_type)
|
||||
// Using _T_ to differentiate between get<string> and get_string
|
||||
// `foo<int>()` => `foo_T_int()`
|
||||
name += '_T_' + g.typ(node.generic_type)
|
||||
}
|
||||
// TODO2
|
||||
// cgen shouldn't modify ast nodes, this should be moved
|
||||
|
12
vlib/v/tests/generic_functions_with_normal_function_test.v
Normal file
12
vlib/v/tests/generic_functions_with_normal_function_test.v
Normal file
@ -0,0 +1,12 @@
|
||||
fn get<T>(typ T) T {
|
||||
return typ
|
||||
}
|
||||
|
||||
fn get_string(typ string) string {
|
||||
return 'boom'
|
||||
}
|
||||
|
||||
fn test_generic_with_same_type() {
|
||||
assert get_string('') == 'boom'
|
||||
assert get<string>('hello') == 'hello'
|
||||
}
|
Loading…
Reference in New Issue
Block a user