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

cgen: fix using 'array' name variable in array_init (#16168)

This commit is contained in:
yuyi 2022-10-24 03:23:15 +08:00 committed by GitHub
parent 340611c298
commit 7b8044b8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -1601,3 +1601,9 @@ fn test_2d_array_init_with_it() {
a := [][]int{len: 6, init: f(it, 2 * it)}
assert a == [[0, 0], [1, 2], [2, 4], [3, 6], [4, 8], [5, 10]]
}
fn test_using_array_name_variable() {
array := []int{len: 4, init: it}
println(array)
assert array == [0, 1, 2, 3]
}

View File

@ -448,7 +448,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.is_shared = var_type.has_flag(.shared_f)
if is_fixed_array_init && !has_val {
if val is ast.ArrayInit {
g.array_init(val, ident.name)
g.array_init(val, c_name(ident.name))
} else {
g.write('{0}')
}
@ -460,7 +460,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.write('*')
}
if val is ast.ArrayInit {
g.array_init(val, ident.name)
g.array_init(val, c_name(ident.name))
} else if val_type.has_flag(.shared_f) {
g.expr_with_cast(val, val_type, var_type)
} else {