From 227f03965238bf3f08482d28127c94a312e7e73d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 21 May 2020 18:36:25 +0200 Subject: [PATCH] vfmt: handle generic fn calls --- vlib/v/fmt/fmt.v | 8 +++++++- vlib/v/tests/generic_test.v | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 4c2f11aa60..b22742eed8 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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) diff --git a/vlib/v/tests/generic_test.v b/vlib/v/tests/generic_test.v index cdbe1c5d86..984800e743 100644 --- a/vlib/v/tests/generic_test.v +++ b/vlib/v/tests/generic_test.v @@ -5,11 +5,17 @@ fn simple(p T) T { return p } +fn plus(a, b T) T { + // q := a + 1 + return a + b +} + fn test_generic_fn() { assert simple(1) == 1 assert simple(1 + 0) == 1 assert simple('g') == 'g' assert simple('g') + 'h' == 'gh' + // plus(2, 3) } /* @@ -37,10 +43,6 @@ fn foldl(l []T, nil T, f fn(T,T)T) T { return r } -fn plus(a T, b T) T { - return a+b -} - fn square(x int) int { return x*x }