Commit dea3ce87

dea3ce875d95Merged

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

Description

fix(codegen): case-expr scrutinee unboxes bigint to mrb_int before when-cmp

compile_case_stmt and compile_case_return fell through to a generic mrb_int <tmp> = <pred_val>; for non-string/obj/poly/ range/float/bool predicates. With promote mode widening an Integer predicate to sp_Bigint *, the assignment then failed -Wint-conversion.

Add an explicit bigint arm that unboxes via sp_bigint_to_int before the when-arm comparisons (which are still int-shaped: literal value or Range integer endpoints). Sets pred_type back to "int" locally so compile_when_conds picks the int-cmp path.

Promote-mode test count: 467 pass / 46 fail / 105 error -> 470 pass / 46 fail / 102 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
dea3ce875d95
Parent
54c24da867ae

spinel_codegen.rbmodifiedView file

@@ -26524,6 +26524,14 @@
2652426524 # struct value to an int, tripping the C compiler. Issue #604
2652526525 # sibling: a case as a function tail with a Range scrutinee.
2652626526 emit(" " + c_type(pred_type) + " " + tmp + " = " + pred_val + ";")
26527+ elsif pred_type == "bigint"
26528+ # promote-mode-widened predicate: keep the temp typed as
26529+ # bigint and unbox to mrb_int for the when comparisons via
26530+ # the compile_when_conds path (which already handles the
26531+ # bigint cmp through sp_bigint_to_int when needed).
26532+ @needs_bigint = 1
26533+ emit(" mrb_int " + tmp + " = sp_bigint_to_int((sp_Bigint *)" + pred_val + ");")
26534+ pred_type = "int"
2652726535 else
2652826536 emit(" mrb_int " + tmp + " = " + pred_val + ";")
2652926537 end
@@ -35691,6 +35699,10 @@
3569135699 bt_cr = base_type(pred_type)
3569235700 cn_cr = bt_cr[4, bt_cr.length - 4]
3569335701 emit(" sp_" + cn_cr + " *" + tmp + " = " + pred_val + ";")
35702+ elsif pred_type == "bigint"
35703+ @needs_bigint = 1
35704+ emit(" mrb_int " + tmp + " = sp_bigint_to_int((sp_Bigint *)" + pred_val + ");")
35705+ pred_type = "int"
3569435706 else
3569535707 emit(" mrb_int " + tmp + " = " + pred_val + ";")
3569635708 end