mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fixed array of string item concatenation (#17801)
This commit is contained in:
parent
da153aa780
commit
db8331da24
@ -419,10 +419,16 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
|||||||
mut op_expected_left := ast.Type(0)
|
mut op_expected_left := ast.Type(0)
|
||||||
mut op_expected_right := ast.Type(0)
|
mut op_expected_right := ast.Type(0)
|
||||||
if node.op == .plus_assign && unaliased_right_sym.kind == .string {
|
if node.op == .plus_assign && unaliased_right_sym.kind == .string {
|
||||||
if left is ast.IndexExpr {
|
if mut left is ast.IndexExpr {
|
||||||
// a[0] += str => `array_set(&a, 0, &(string[]) {string__plus(...))})`
|
if g.table.sym(left.left_type).kind == .array_fixed {
|
||||||
g.expr(left)
|
// strs[0] += str2 => `strs[0] = string__plus(strs[0], str2)`
|
||||||
g.write('string__plus(')
|
g.expr(left)
|
||||||
|
g.write(' = string__plus(')
|
||||||
|
} else {
|
||||||
|
// a[0] += str => `array_set(&a, 0, &(string[]) {string__plus(...))})`
|
||||||
|
g.expr(left)
|
||||||
|
g.write('string__plus(')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// str += str2 => `str = string__plus(str, str2)`
|
// str += str2 => `str = string__plus(str, str2)`
|
||||||
g.expr(left)
|
g.expr(left)
|
||||||
|
11
vlib/v/tests/array_string_test.v
Normal file
11
vlib/v/tests/array_string_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn test_array() {
|
||||||
|
mut strs := ['abc', 'cde']!
|
||||||
|
strs[0] += 'def'
|
||||||
|
assert strs[0] == 'abcdef'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_fixed_array() {
|
||||||
|
mut strs := ['abc', 'cde']
|
||||||
|
strs[0] += 'def'
|
||||||
|
assert strs[0] == 'abcdef'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user