From ee7bcfd05cc1743ef1f5b37f91473a35257583fa Mon Sep 17 00:00:00 2001 From: Henrixounez <30901439+Henrixounez@users.noreply.github.com> Date: Sun, 18 Apr 2021 15:26:40 +0200 Subject: [PATCH] =?UTF-8?q?checker:=20prevent=20double=20module=20name=20p?= =?UTF-8?q?repending=20on=20generics=20types=20regi=E2=80=A6=20(#9791)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vlib/v/checker/checker.v | 2 +- vlib/v/tests/generics_in_generics_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/generics_in_generics_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c8a90c36e3..ab61db3a1c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1929,7 +1929,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type { } } if has_generic_generic { - if c.mod != '' { + if c.mod != '' && !fn_name.starts_with('${c.mod}.') { // Need to prepend the module when adding a generic type to a function c.table.register_fn_generic_types(c.mod + '.' + fn_name, generic_types) } else { diff --git a/vlib/v/tests/generics_in_generics_test.v b/vlib/v/tests/generics_in_generics_test.v new file mode 100644 index 0000000000..3e2149d548 --- /dev/null +++ b/vlib/v/tests/generics_in_generics_test.v @@ -0,0 +1,12 @@ +fn gen_fn2(e T) string { + return '$e.str()' +} + +fn gen_fn(e T) string { + return gen_fn2(e) +} + +fn test_generics_in_generics() { + assert gen_fn(u64(42)) == '42' + assert gen_fn('42') == '42' +}