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

cgen: fix strings builder shift array.reverse() (#17979)

This commit is contained in:
yuyi 2023-04-17 19:06:57 +08:00 committed by GitHub
parent 4a22d4a65d
commit fe4ccbc4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -741,8 +741,9 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
tmp_var := g.new_tmp_var()
array_info := left.unaliased_sym.info as ast.Array
noscan := g.check_noscan(array_info.elem_type)
if right.unaliased_sym.kind == .array && array_info.elem_type != right.typ
&& !(right.sym.kind == .alias
if (right.unaliased_sym.kind == .array
|| (right.unaliased_sym.kind == .struct_ && right.unaliased_sym.name == 'array'))
&& array_info.elem_type != right.typ && !(right.sym.kind == .alias
&& g.table.sumtype_has_variant(array_info.elem_type, node.right_type, false)) {
// push an array => PUSH_MANY, but not if pushing an array to 2d array (`[][]int << []int`)
g.write('_PUSH_MANY${noscan}(')

View File

@ -0,0 +1,12 @@
import rand
import strings
fn test_strings_builder_shift_array_reverse() {
mut a := strings.new_builder(0)
mut b := strings.new_builder(0)
b << rand.ascii(5).bytes()
a << b.reverse()
ret := a.str()
println(ret)
assert ret.len == 5
}