Skip to content

Commit 0f16983

Browse files
committed
fix
1 parent 76d43da commit 0f16983

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

vlib/v/gen/c/assign.v

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
526526
} else {
527527
g.write('{${styp} _ = ')
528528
}
529-
if val !in [ast.StructInit, ast.ArrayInit]
530-
&& unaliased_right_sym.info is ast.ArrayFixed {
529+
if val in [ast.MatchExpr, ast.IfExpr] && unaliased_right_sym.info is ast.ArrayFixed {
531530
tmp_var := g.expr_with_var(val, var_type, false)
532531
g.fixed_array_var_init(tmp_var, false, unaliased_right_sym.info.elem_type,
533532
unaliased_right_sym.info.size)
@@ -918,6 +917,11 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
918917
g.array_init(val, c_name(ident.name))
919918
} else if val_type.has_flag(.shared_f) {
920919
g.expr_with_cast(val, val_type, var_type)
920+
} else if val in [ast.MatchExpr, ast.IfExpr]
921+
&& unaliased_right_sym.info is ast.ArrayFixed {
922+
tmp_var := g.expr_with_var(val, var_type, false)
923+
g.fixed_array_var_init(tmp_var, false, unaliased_right_sym.info.elem_type,
924+
unaliased_right_sym.info.size)
921925
} else {
922926
g.expr(val)
923927
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
fn test_main() {
22
_ := if true { [0]! } else { [1]! }
33
_ := if true { [0] } else { [1] }
4+
5+
a := if true { [0]! } else { [1]! }
6+
b := if true { [0] } else { [1] }
7+
dump(a)
8+
dump(b)
9+
}
10+
11+
fn test_match() {
12+
grid_size := 1
13+
14+
_ := match grid_size {
15+
3 { ['Small', '3x3']! }
16+
4 { ['Classic', '4x4']! }
17+
5 { ['Big', '5x5']! }
18+
else { ['Large', '6x6']! }
19+
}
20+
21+
w := match grid_size {
22+
3 { ['Small', '3x3']! }
23+
4 { ['Classic', '4x4']! }
24+
5 { ['Big', '5x5']! }
25+
else { ['Large', '6x6']! }
26+
}
27+
dump(w)
428
}

0 commit comments

Comments
 (0)