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

cgen: fix multi_array prepend/insert (#7381)

This commit is contained in:
yuyi 2020-12-19 14:28:15 +08:00 committed by GitHub
parent 598d18cbd9
commit e4973782b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -1181,3 +1181,23 @@ fn test_voidptr_vbytes() {
println(bytes) println(bytes)
} }
} }
fn test_multi_array_prepend() {
mut a := [][]int{}
a.prepend([1, 2, 3])
assert a == [[1, 2, 3]]
mut b := [][]int{}
b.prepend([[1, 2, 3]])
assert b == [[1, 2, 3]]
}
fn test_multi_array_insert() {
mut a := [][]int{}
a.insert(0, [1, 2, 3])
assert a == [[1, 2, 3]]
mut b := [][]int{}
b.insert(0, [[1, 2, 3]])
assert b == [[1, 2, 3]]
}

View File

@ -5041,7 +5041,7 @@ fn (mut g Gen) gen_array_insert(node ast.CallExpr) {
left_info := left_sym.info as table.Array left_info := left_sym.info as table.Array
elem_type_str := g.typ(left_info.elem_type) elem_type_str := g.typ(left_info.elem_type)
arg2_sym := g.table.get_type_symbol(node.args[1].typ) arg2_sym := g.table.get_type_symbol(node.args[1].typ)
is_arg2_array := arg2_sym.kind == .array is_arg2_array := arg2_sym.kind == .array && node.args[1].typ == node.left_type
if is_arg2_array { if is_arg2_array {
g.write('array_insert_many(&') g.write('array_insert_many(&')
} else { } else {
@ -5075,7 +5075,7 @@ fn (mut g Gen) gen_array_prepend(node ast.CallExpr) {
left_info := left_sym.info as table.Array left_info := left_sym.info as table.Array
elem_type_str := g.typ(left_info.elem_type) elem_type_str := g.typ(left_info.elem_type)
arg_sym := g.table.get_type_symbol(node.args[0].typ) arg_sym := g.table.get_type_symbol(node.args[0].typ)
is_arg_array := arg_sym.kind == .array is_arg_array := arg_sym.kind == .array && node.args[0].typ == node.left_type
if is_arg_array { if is_arg_array {
g.write('array_prepend_many(&') g.write('array_prepend_many(&')
} else { } else {