From 82d4ba67b36e739d3a7805338845605b4315aaf1 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 5 Nov 2025 23:07:57 +0800 Subject: [PATCH] cgen: fix multi generics fn name (fix #23886) (#25673) --- vlib/v/gen/c/fn.v | 4 ++- ...enerics_with_multi_generics_fn_name_test.v | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/generics/generics_with_multi_generics_fn_name_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 72735e305..07e51a1a2 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -7,7 +7,9 @@ import strings import v.ast import v.util -const c_fn_name_escape_seq = ['[', '_T_', ']', ''] +// has[int]() => has_T_int() +// has[int, string]() => has_T_int_string() +const c_fn_name_escape_seq = ['[', '_T_', ', ', '_', ']', ''] fn (mut g Gen) is_used_by_main(node ast.FnDecl) bool { $if trace_unused_by_main ? { diff --git a/vlib/v/tests/generics/generics_with_multi_generics_fn_name_test.v b/vlib/v/tests/generics/generics_with_multi_generics_fn_name_test.v new file mode 100644 index 000000000..df57dd245 --- /dev/null +++ b/vlib/v/tests/generics/generics_with_multi_generics_fn_name_test.v @@ -0,0 +1,35 @@ +pub struct ValueWithErrors[T, E] { +pub: + value T + errors E +} + +@[inline] +pub fn (self ValueWithErrors[T, E]) has_errors() bool { + return self.errors.len > 0 +} + +pub fn transform_and_validate[T](data map[string]string) ValueWithErrors[T, map[string][]IError] { + mut new_object := T{} + mut errors := map[string][]IError{} + return ValueWithErrors[T, map[string][]IError]{ + errors: errors + value: new_object + } +} + +struct BasicStruct { + str string @[max_length: 15; min_length: 3; req] + number int @[max: 100; min: 3; req] + b bool @[req] +} + +fn test_generics_with_multi_generics_fn_name() { + data_with_errors := transform_and_validate[BasicStruct]({ + 'str': '1234567890123456' + 'number': '11' + }) + + dump(data_with_errors) + assert data_with_errors.errors.len == 0 +} -- 2.39.5