Skip to content

Commit fe4ccbc

Browse files
authored
cgen: fix strings builder shift array.reverse() (#17979)
1 parent 4a22d4a commit fe4ccbc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

vlib/v/gen/c/infix.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,9 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
741741
tmp_var := g.new_tmp_var()
742742
array_info := left.unaliased_sym.info as ast.Array
743743
noscan := g.check_noscan(array_info.elem_type)
744-
if right.unaliased_sym.kind == .array && array_info.elem_type != right.typ
745-
&& !(right.sym.kind == .alias
744+
if (right.unaliased_sym.kind == .array
745+
|| (right.unaliased_sym.kind == .struct_ && right.unaliased_sym.name == 'array'))
746+
&& array_info.elem_type != right.typ && !(right.sym.kind == .alias
746747
&& g.table.sumtype_has_variant(array_info.elem_type, node.right_type, false)) {
747748
// push an array => PUSH_MANY, but not if pushing an array to 2d array (`[][]int << []int`)
748749
g.write('_PUSH_MANY${noscan}(')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import rand
2+
import strings
3+
4+
fn test_strings_builder_shift_array_reverse() {
5+
mut a := strings.new_builder(0)
6+
mut b := strings.new_builder(0)
7+
b << rand.ascii(5).bytes()
8+
a << b.reverse()
9+
ret := a.str()
10+
println(ret)
11+
assert ret.len == 5
12+
}

0 commit comments

Comments
 (0)