1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: handle generic fn calls

This commit is contained in:
Alexander Medvednikov 2020-05-21 18:36:25 +02:00
parent 87d8e70d6d
commit 227f039652
2 changed files with 13 additions and 5 deletions

View File

@ -849,7 +849,13 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
} else {
name := short_module(node.name)
f.mark_module_as_used(name)
f.write('${name}(')
f.write('${name}')
if node.generic_type != 0 && node.generic_type != table.void_type {
f.write('<')
f.write(f.type_to_str(node.generic_type))
f.write('>')
}
f.write('(')
f.call_args(node.args)
f.write(')')
f.or_expr(node.or_block)

View File

@ -5,11 +5,17 @@ fn simple<T>(p T) T {
return p
}
fn plus<T>(a, b T) T {
// q := a + 1
return a + b
}
fn test_generic_fn() {
assert simple<int>(1) == 1
assert simple<int>(1 + 0) == 1
assert simple<string>('g') == 'g'
assert simple<string>('g') + 'h' == 'gh'
// plus<int>(2, 3)
}
/*
@ -37,10 +43,6 @@ fn foldl<T>(l []T, nil T, f fn(T,T)T) T {
return r
}
fn plus<T>(a T, b T) T {
return a+b
}
fn square(x int) int {
return x*x
}