mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix string of map with generic struct value (#16595)
This commit is contained in:
parent
a96e2e7093
commit
e35f5f290e
@ -709,8 +709,18 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
|
|||||||
val_sym = g.table.sym(val_typ)
|
val_sym = g.table.sym(val_typ)
|
||||||
}
|
}
|
||||||
val_styp := g.typ(val_typ)
|
val_styp := g.typ(val_typ)
|
||||||
elem_str_fn_name := val_styp.replace('*', '') + '_str'
|
mut elem_str_fn_name := val_styp.replace('*', '') + '_str'
|
||||||
if !val_sym.has_method('str') {
|
if val_sym.has_method_with_generic_parent('str') {
|
||||||
|
match mut val_sym.info {
|
||||||
|
ast.Struct, ast.Interface, ast.SumType {
|
||||||
|
if val_sym.info.generic_types.len > 0 {
|
||||||
|
elem_str_fn_name = g.generic_fn_name(val_sym.info.concrete_types,
|
||||||
|
elem_str_fn_name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
g.get_str_fn(val_typ)
|
g.get_str_fn(val_typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -742,7 +752,7 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
|
|||||||
} else if val_sym.kind == .string {
|
} else if val_sym.kind == .string {
|
||||||
tmp_str := str_intp_sq('*(${val_styp}*)DenseArray_value(&m.key_values, i)')
|
tmp_str := str_intp_sq('*(${val_styp}*)DenseArray_value(&m.key_values, i)')
|
||||||
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${tmp_str});')
|
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${tmp_str});')
|
||||||
} else if should_use_indent_func(val_sym.kind) && !val_sym.has_method('str') {
|
} else if should_use_indent_func(val_sym.kind) && !val_sym.has_method_with_generic_parent('str') {
|
||||||
ptr_str := '*'.repeat(val_typ.nr_muls())
|
ptr_str := '*'.repeat(val_typ.nr_muls())
|
||||||
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, indent_${elem_str_fn_name}(*${ptr_str}(${val_styp}*)DenseArray_value(&m.key_values, i), indent_count));')
|
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, indent_${elem_str_fn_name}(*${ptr_str}(${val_styp}*)DenseArray_value(&m.key_values, i), indent_count));')
|
||||||
} else if val_sym.kind in [.f32, .f64] {
|
} else if val_sym.kind in [.f32, .f64] {
|
||||||
|
7
vlib/v/tests/string_map_with_generic_struct_value_test.v
Normal file
7
vlib/v/tests/string_map_with_generic_struct_value_test.v
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import datatypes
|
||||||
|
|
||||||
|
fn test_string_map_with_generic_struct_value() {
|
||||||
|
p := map[string]datatypes.Stack[int]{}
|
||||||
|
println(p)
|
||||||
|
assert '${p}' == '{}'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user