Skip to content

Commit 82d4ba6

Browse files
authored
cgen: fix multi generics fn name (fix #23886) (#25673)
1 parent ad74a86 commit 82d4ba6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

vlib/v/gen/c/fn.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import strings
77
import v.ast
88
import v.util
99

10-
const c_fn_name_escape_seq = ['[', '_T_', ']', '']
10+
// has[int]() => has_T_int()
11+
// has[int, string]() => has_T_int_string()
12+
const c_fn_name_escape_seq = ['[', '_T_', ', ', '_', ']', '']
1113

1214
fn (mut g Gen) is_used_by_main(node ast.FnDecl) bool {
1315
$if trace_unused_by_main ? {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pub struct ValueWithErrors[T, E] {
2+
pub:
3+
value T
4+
errors E
5+
}
6+
7+
@[inline]
8+
pub fn (self ValueWithErrors[T, E]) has_errors() bool {
9+
return self.errors.len > 0
10+
}
11+
12+
pub fn transform_and_validate[T](data map[string]string) ValueWithErrors[T, map[string][]IError] {
13+
mut new_object := T{}
14+
mut errors := map[string][]IError{}
15+
return ValueWithErrors[T, map[string][]IError]{
16+
errors: errors
17+
value: new_object
18+
}
19+
}
20+
21+
struct BasicStruct {
22+
str string @[max_length: 15; min_length: 3; req]
23+
number int @[max: 100; min: 3; req]
24+
b bool @[req]
25+
}
26+
27+
fn test_generics_with_multi_generics_fn_name() {
28+
data_with_errors := transform_and_validate[BasicStruct]({
29+
'str': '1234567890123456'
30+
'number': '11'
31+
})
32+
33+
dump(data_with_errors)
34+
assert data_with_errors.errors.len == 0
35+
}

0 commit comments

Comments
 (0)