mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix pushing to an array of string pointers (fix #14156)
This commit is contained in:
parent
922cee9162
commit
147e6e669f
@ -708,7 +708,8 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
|
||||
g.write(', _MOV(($elem_type_str[]){ ')
|
||||
}
|
||||
// if g.autofree
|
||||
needs_clone := array_info.elem_type.idx() == ast.string_type_idx && !g.is_builtin_mod
|
||||
needs_clone := !g.is_builtin_mod && array_info.elem_type.idx() == ast.string_type_idx
|
||||
&& array_info.elem_type.nr_muls() == 0
|
||||
if needs_clone {
|
||||
g.write('string_clone(')
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
fn test_str_array_of_reference() {
|
||||
fn test_creating_an_array_of_string_reference() {
|
||||
names := ['John', 'Paul', 'George', 'Ringo']
|
||||
a := unsafe { [&names[0], &names[1]] }
|
||||
println(a[0])
|
||||
println(a)
|
||||
assert '$a' == "[&'John', &'Paul']"
|
||||
assert typeof(a[0]).name == '&string'
|
||||
}
|
||||
|
||||
fn test_pushing_to_an_array_of_string_references() {
|
||||
mut a := []&string{}
|
||||
v1 := 'abc'
|
||||
v2 := 'def'
|
||||
a << &v1
|
||||
a << &v2
|
||||
assert *(a[0]) == 'abc'
|
||||
assert *(a[1]) == 'def'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user