1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix printing map reference value (#17496)

This commit is contained in:
yuyi 2023-03-04 17:35:38 +08:00 committed by GitHub
parent 6f7192359a
commit 30c205ef2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -759,7 +759,8 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
tmp_str := str_intp_rune('${elem_str_fn_name}(*(${val_styp}*)DenseArray_value(&m.key_values, i))')
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${tmp_str});')
} else {
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(*(${val_styp}*)DenseArray_value(&m.key_values, i)));')
ptr_str := '*'.repeat(val_typ.nr_muls())
g.auto_str_funcs.writeln('\t\tstrings__Builder_write_string(&sb, ${elem_str_fn_name}(*${ptr_str}(${val_styp}*)DenseArray_value(&m.key_values, i)));')
}
g.auto_str_funcs.writeln('\t\tif (i != m.key_values.len-1) {')
g.auto_str_funcs.writeln('\t\t\tstrings__Builder_write_string(&sb, _SLIT(", "));')

View File

@ -1,3 +1,5 @@
import datatypes
struct Foo {
bar string
}
@ -15,3 +17,9 @@ fn test_map_reference_value() {
assert true
}
fn test_map_reference_value2() {
mut m := map[string]&datatypes.Queue[i64]{}
println('${m}')
assert '${m}' == '{}'
}