From ec47cda3861fd34f418bb46ff68473fc33a2e62b Mon Sep 17 00:00:00 2001 From: crthpl <56052645+crthpl@users.noreply.github.com> Date: Sat, 17 Jul 2021 01:51:42 -0700 Subject: [PATCH] cgen: fix other generic pointer cases (#10834) --- vlib/v/gen/c/cgen.v | 8 ++------ vlib/v/tests/generics_test.v | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 771202193e..085d80ce73 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -581,7 +581,7 @@ fn (mut g Gen) base_type(t ast.Type) string { if t.has_flag(.shared_f) { styp = g.find_or_register_shared(t, styp) } - nr_muls := t.nr_muls() + nr_muls := g.unwrap_generic(t).nr_muls() if nr_muls > 0 { styp += strings.repeat(`*`, nr_muls) } @@ -596,11 +596,7 @@ fn (mut g Gen) generic_fn_name(types []ast.Type, before string, is_decl bool) st // `foo()` => `foo_T_int()` mut name := before + '_T' for typ in types { - nr_muls := typ.nr_muls() - if is_decl && nr_muls > 0 { - name = strings.repeat(`*`, nr_muls) + name - } - name += '_' + strings.repeat_string('__ptr__', nr_muls) + g.typ(typ.set_nr_muls(0)) + name += '_' + strings.repeat_string('__ptr__', typ.nr_muls()) + g.typ(typ.set_nr_muls(0)) } return name } diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index c6b5a68487..714d4ea540 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -16,7 +16,10 @@ fn test_identity() { })['a'] == 'b' assert simple(simplemodule.Data{ value: 8 }).value == 8 - assert simple<&simplemodule.Data>(&simplemodule.Data{ value: 123 }).value == 123 + x := &simplemodule.Data{ + value: 123 + } + assert simple<&simplemodule.Data>(x).value == 123 } fn plus(xxx T, b T) T {