Commit 2d46808b

2d46808b2d42Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): case-as-expression form unboxes bigint scrutinee

compile_expr's CaseNode arm (the value-producing form, used when case is on the rhs of an assignment) fell through to the generic c_type(pred_type) <tmp> = <val>; branch for non-string/obj/poly scrutinees. With promote mode widening an Integer scrutinee to sp_Bigint *, the subsequent when-arm comparisons against int literals (== 1LL, range endpoints, etc.) tripped pointer/int comparisons.

Mirror the compile_case_stmt fix: add an explicit bigint arm that unboxes to mrb_int via sp_bigint_to_int and rewrites pred_type to "int" locally so the when-arm dispatch picks the int compare path.

Promote-mode test count: 497 pass / 43 fail / 78 error -> 499 pass / 43 fail / 76 error. Default raise mode unchanged at 618 / 0 / 0.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
2d46808b2d42
Parent
898cee72860c

spinel_codegen.rbmodifiedView file

@@ -11926,6 +11926,13 @@
1192611926 # uses, but the scrutinee temp must follow pred_type.
1192711927 @needs_rb_value = 1
1192811928 emit(" sp_RbVal " + ptmp + " = " + pred_val + ";")
11929+ elsif pred_type == "bigint"
11930+ # promote-mode-widened scrutinee: when-arms compare against
11931+ # int literals / ranges, so unbox to mrb_int up front and
11932+ # treat the temp as int for the when dispatch.
11933+ @needs_bigint = 1
11934+ emit(" mrb_int " + ptmp + " = sp_bigint_to_int((sp_Bigint *)" + pred_val + ");")
11935+ pred_type = "int"
1192911936 else
1193011937 emit(" " + c_type(pred_type) + " " + ptmp + " = " + pred_val + ";")
1193111938 end