cgen: fix initialization errors with fixed array aliases (#10784)
parent
d1f1c5ae51
commit
2a9d6fef9f
|
@ -2512,9 +2512,12 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
right_sym := g.table.get_type_symbol(g.unwrap_generic(val_type))
|
unwrapped_val_type := g.unwrap_generic(val_type)
|
||||||
is_fixed_array_var := right_sym.kind == .array_fixed && (val is ast.Ident
|
right_sym := g.table.get_type_symbol(unwrapped_val_type)
|
||||||
|| val is ast.IndexExpr || val is ast.CallExpr
|
unaliased_right_sym := g.table.get_final_type_symbol(unwrapped_val_type)
|
||||||
|
is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit
|
||||||
|
&& (val is ast.Ident || val is ast.IndexExpr || val is ast.CallExpr
|
||||||
|
|| (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit)
|
||||||
|| val is ast.SelectorExpr)
|
|| val is ast.SelectorExpr)
|
||||||
g.is_assign_lhs = true
|
g.is_assign_lhs = true
|
||||||
g.assign_op = assign_stmt.op
|
g.assign_op = assign_stmt.op
|
||||||
|
@ -4319,6 +4322,8 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
|
||||||
g.write('*(($styp *)(&')
|
g.write('*(($styp *)(&')
|
||||||
g.expr(node.expr)
|
g.expr(node.expr)
|
||||||
g.write('))')
|
g.write('))')
|
||||||
|
} else if sym.kind == .alias && g.table.get_final_type_symbol(node.typ).kind == .array_fixed {
|
||||||
|
g.expr(node.expr)
|
||||||
} else {
|
} else {
|
||||||
styp := g.typ(node.typ)
|
styp := g.typ(node.typ)
|
||||||
mut cast_label := ''
|
mut cast_label := ''
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
type Tres = [3]int
|
||||||
|
|
||||||
|
fn test_alias_fixed_array_init() {
|
||||||
|
fixed_three := [1, 2, 3]!
|
||||||
|
x := Tres(fixed_three)
|
||||||
|
println(x)
|
||||||
|
assert '$x' == 'Tres([1, 2, 3])'
|
||||||
|
|
||||||
|
y := Tres([2, 3, 4]!)
|
||||||
|
println(y)
|
||||||
|
assert '$y' == 'Tres([2, 3, 4])'
|
||||||
|
}
|
Loading…
Reference in New Issue