Skip to content

Commit e35570a

Browse files
committed
cgen: avoid double generic str suffix for options
1 parent 735f80a commit e35570a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

vlib/v/gen/c/auto_str_methods.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin
12181218
}
12191219
if !g.pref.new_generic_solver {
12201220
if str_method := sym.find_method_with_generic_parent('str') {
1221-
if str_method.generic_names.len > 0 {
1221+
if str_method.generic_names.len > 0 && !ftyp_noshared.has_flag(.option) {
12221222
match sym.info {
12231223
ast.Struct, ast.SumType, ast.Interface, ast.Alias {
12241224
field_fn_name = g.generic_fn_name(g.str_method_concrete_types(ftyp_noshared, sym),

vlib/v/tests/generics/generic_sumtype_str_test.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ struct MaybeContainer[T] {
66
value Maybe[T]
77
}
88

9+
struct MaybeOptionalContainer[T] {
10+
value ?Maybe[T]
11+
}
12+
913
pub fn (m Maybe[T]) str[T]() string {
1014
return if m is T {
1115
x := m as T
@@ -87,3 +91,10 @@ fn test_auto_str_struct_field_with_generic_sumtype_str() {
8791
}
8892
assert '${c}'.contains('value: Some(456)')
8993
}
94+
95+
fn test_auto_str_optional_field_with_generic_sumtype_str() {
96+
c := MaybeOptionalContainer[int]{
97+
value: some(789)
98+
}
99+
assert '${c}'.contains('Some(789)')
100+
}

0 commit comments

Comments
 (0)