cgen: fix error for array of reference auto_str (#13665)
parent
b0f651bf81
commit
c8e33ad219
|
@ -610,7 +610,11 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
|
||||||
// Rune are managed at this level as strings
|
// Rune are managed at this level as strings
|
||||||
g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\`"), $c.si_s_code, {.d_s = ${elem_str_fn_name}(it) }}, {_SLIT("\`"), 0, {.d_c = 0 }}}));\n')
|
g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\`"), $c.si_s_code, {.d_s = ${elem_str_fn_name}(it) }}, {_SLIT("\`"), 0, {.d_c = 0 }}}));\n')
|
||||||
} else if sym.kind == .string {
|
} else if sym.kind == .string {
|
||||||
|
if is_elem_ptr {
|
||||||
|
g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("&\'"), $c.si_s_code, {.d_s = *it }}, {_SLIT("\'"), 0, {.d_c = 0 }}}));\n')
|
||||||
|
} else {
|
||||||
g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\'"), $c.si_s_code, {.d_s = it }}, {_SLIT("\'"), 0, {.d_c = 0 }}}));\n')
|
g.auto_str_funcs.writeln('\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT("\'"), $c.si_s_code, {.d_s = it }}, {_SLIT("\'"), 0, {.d_c = 0 }}}));\n')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// There is a custom .str() method, so use it.
|
// There is a custom .str() method, so use it.
|
||||||
// NB: we need to take account of whether the user has defined
|
// NB: we need to take account of whether the user has defined
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn test_str_array_of_reference() {
|
||||||
|
names := ['John', 'Paul', 'George', 'Ringo']
|
||||||
|
a := unsafe { [&names[0], &names[1]] }
|
||||||
|
println(a[0])
|
||||||
|
println(a)
|
||||||
|
assert '$a' == "[&'John', &'Paul']"
|
||||||
|
}
|
Loading…
Reference in New Issue