Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored and spytheman committed Dec 15, 2024
1 parent ad26992 commit 40715f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -5364,10 +5364,14 @@ 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.styp(node.expr.typ)})')
if node.typ.has_flag(.option) {
g.expr_with_opt(node.expr, expr_type, node.typ)
} else {
if node.expr is ast.ArrayInit && g.assign_op != .decl_assign {
g.write('(${g.styp(node.expr.typ)})')
}
g.expr(node.expr)
}
g.expr(node.expr)
} else if expr_type == ast.bool_type && node.typ.is_int() {
styp := g.styp(node_typ)
g.write('(${styp}[]){(')
Expand Down
24 changes: 24 additions & 0 deletions vlib/v/tests/alias_cast_to_fixed_array_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type Bytes = [3]u8
type Strs = [3]string

fn test_none() {
b := ?Bytes(none)
println(b)
assert b == none

c := ?Strs(none)
println(c)
assert c == none
}

fn test_non_none() {
b := ?Bytes([u8(1), 2, 3]!)
println(b)
assert b != none
assert b?[2] == 3

c := ?Strs(['a', 'b', 'c']!)
println(c)
assert c != none
assert c?[2] == 'c'
}

0 comments on commit 40715f0

Please sign in to comment.