Commit ae80180a

ae80180a3f90Merged

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

Description

fix(codegen): LV write as expression coerces int<->bigint at slot boundary

compile_expr's LocalVariableWriteNode arm (used as a side-effect expression — while (n = gets.to_i) > 0 etc.) emitted (lv = val) raw. With promote-mode n widened to sp_Bigint * and rhs gets.to _i returning mrb_int, the assignment tripped -Wint-conversion in the while predicate.

Mirror the int <-> bigint coerce already in compile_stmt's LVW.

Promote-mode test count: 535 pass / 53 fail / 30 error -> 536 pass / 53 fail / 29 error. Default raise mode 618 / 0 / 0.

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

Details

Commit
ae80180a3f90
Parent
86e03011912e

spinel_codegen.rbmodifiedView file

@@ -11588,6 +11588,16 @@
1158811588 if vt == "poly" && rhs_t != "" && rhs_t != "poly"
1158911589 val = box_value_to_poly(rhs_t, val)
1159011590 end
11591+ # promote-mode bigint slot: coerce an int rhs (literal, mrb_int-
11592+ # returning call like `gets.to_i`) before the C-level assign.
11593+ # Mirrors compile_stmt's LVW arm.
11594+ if vt == "bigint" && rhs_t == "int"
11595+ @needs_bigint = 1
11596+ val = "sp_bigint_new_int(" + val + ")"
11597+ elsif vt == "int" && rhs_t == "bigint"
11598+ @needs_bigint = 1
11599+ val = "sp_bigint_to_int((sp_Bigint *)" + val + ")"
11600+ end
1159111601 return "(" + fiber_var_ref(lname2) + " = " + val + ")"
1159211602 end
1159311603 if t == "LocalVariableOperatorWriteNode"