File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -2060,9 +2060,14 @@ let generate_c_expression ctx ir_expr =
2060
2060
(* Generate temporary variable for the result *)
2061
2061
emit_line ctx (sprintf " %s %s;" result_type temp_var);
2062
2062
2063
- (* Generate if-else chain *)
2064
- let generate_match_arm is_first arm =
2063
+ (* Pre-generate all string literals to avoid declarations in the middle of if-else chain *)
2064
+ let arm_value_strings = List. map ( fun arm ->
2065
2065
let arm_val_str = generate_c_value ctx arm.ir_arm_value in
2066
+ (arm, arm_val_str)
2067
+ ) arms in
2068
+
2069
+ (* Generate if-else chain *)
2070
+ let generate_match_arm is_first (arm , arm_val_str ) =
2066
2071
match arm.ir_arm_pattern with
2067
2072
| IRConstantPattern const_val ->
2068
2073
let const_str = generate_c_value ctx const_val in
@@ -2081,7 +2086,7 @@ let generate_c_expression ctx ir_expr =
2081
2086
in
2082
2087
2083
2088
(* Generate all arms *)
2084
- (match arms with
2089
+ (match arm_value_strings with
2085
2090
| [] -> () (* No arms - should not happen *)
2086
2091
| first_arm :: rest_arms ->
2087
2092
generate_match_arm true first_arm;
You can’t perform that action at this time.
0 commit comments