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

cgen: fix fixed array assignment from unsafe block (#17647)

This commit is contained in:
Felipe Pena 2023-03-15 15:30:49 -03:00 committed by GitHub
parent 39e80afab0
commit 93a2ffa9ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -329,7 +329,8 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
unaliased_right_sym := g.table.final_sym(unwrapped_val_type) unaliased_right_sym := g.table.final_sym(unwrapped_val_type)
is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit
&& (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr] && (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr]
|| (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit)) || (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit)
|| (val is ast.UnsafeExpr && (val as ast.UnsafeExpr).expr is ast.Ident))
&& !g.pref.translated && !g.pref.translated
g.is_assign_lhs = true g.is_assign_lhs = true
g.assign_op = node.op g.assign_op = node.op

View File

@ -0,0 +1,11 @@
fn test_fixed_array_on_unsafe_int() {
x := [3]int{}
y := unsafe { x }
assert x == [0, 0, 0]!
}
fn test_fixed_array_on_unsafe_string() {
x := [3]string{init: ''}
y := unsafe { x }
assert x == ['', '', '']!
}