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

cgen: fix error for printing aliases of multi fixed array (#14348)

This commit is contained in:
yuyi 2022-05-10 19:03:18 +08:00 committed by GitHub
parent 606d8cfaca
commit 5697d4375b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,9 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
mut return_type := ast.void_type
is_decl := node.op == .decl_assign
g.assign_op = node.op
defer {
g.assign_op = .unknown
}
op := if is_decl { token.Kind.assign } else { node.op }
right_expr := node.right[0]
match right_expr {

View File

@ -3883,6 +3883,9 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
g.expr(node.expr)
g.write('))')
} else if sym.kind == .alias && g.table.final_sym(node.typ).kind == .array_fixed {
if node.expr is ast.ArrayInit && g.assign_op != .decl_assign {
g.write('(${g.typ(node.expr.typ)})')
}
g.expr(node.expr)
} else if node.expr_type == ast.bool_type && node.typ.is_int() {
styp := g.typ(node.typ)

View File

@ -0,0 +1,2 @@
Mat([[1, 2], [3, 4]])
Mat([[1, 2], [3, 4]])

View File

@ -0,0 +1,7 @@
type Mat = [2][2]int
fn main() {
a := Mat([[1, 2]!, [3, 4]!]!)
println(a)
println(Mat([[1, 2]!, [3, 4]!]!))
}