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:
parent
87d8e70d6d
commit
227f039652
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user