Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Feb 10, 2025
1 parent 76d43da commit 0f16983
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
} else {
g.write('{${styp} _ = ')
}
if val !in [ast.StructInit, ast.ArrayInit]
&& unaliased_right_sym.info is ast.ArrayFixed {
if val in [ast.MatchExpr, ast.IfExpr] && unaliased_right_sym.info is ast.ArrayFixed {
tmp_var := g.expr_with_var(val, var_type, false)
g.fixed_array_var_init(tmp_var, false, unaliased_right_sym.info.elem_type,
unaliased_right_sym.info.size)
Expand Down Expand Up @@ -918,6 +917,11 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
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 if val in [ast.MatchExpr, ast.IfExpr]
&& unaliased_right_sym.info is ast.ArrayFixed {
tmp_var := g.expr_with_var(val, var_type, false)
g.fixed_array_var_init(tmp_var, false, unaliased_right_sym.info.elem_type,
unaliased_right_sym.info.size)
} else {
g.expr(val)
}
Expand Down
24 changes: 24 additions & 0 deletions vlib/v/tests/array_fixed_ternary_test.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
fn test_main() {
_ := if true { [0]! } else { [1]! }
_ := if true { [0] } else { [1] }

a := if true { [0]! } else { [1]! }
b := if true { [0] } else { [1] }
dump(a)
dump(b)
}

fn test_match() {
grid_size := 1

_ := match grid_size {
3 { ['Small', '3x3']! }
4 { ['Classic', '4x4']! }
5 { ['Big', '5x5']! }
else { ['Large', '6x6']! }
}

w := match grid_size {
3 { ['Small', '3x3']! }
4 { ['Classic', '4x4']! }
5 { ['Big', '5x5']! }
else { ['Large', '6x6']! }
}
dump(w)
}

0 comments on commit 0f16983

Please sign in to comment.