Commit d963af26

d963af260d92Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · ~4 modified

Description

Fix rescue-modifier expr, TY_EXCEPTION puts, full_message, ensure/return

Five fixes bundled:

  1. RescueModifierNode as rvalue: add inference in analyze.c and full GCC-statement-expression codegen in codegen.c, handling diverging raise arms (TY_VOID guard).

  2. puts/print with TY_EXCEPTION argument: add a dedicated arm to emit_puts_one that calls sp_exc_message().

  3. Exception#full_message: emit "ClassName: message" via sp_sprintf instead of falling through to sp_exc_message (which omits the class).

  4. ensure/return deferred mechanism: introduce EnsureCtx stack in codegen.c so that return inside begin..ensure replaces the bare C return with a flag-and-goto to the ensure label, which then runs the ensure code and only returns afterward. Nested ensures propagate the flag outward. emit_proc_literal saves/restores g_ensure_depth.

  5. String#to_i uses sp_str_to_i_cruby (CRuby-compatible 0-for-invalid) instead of sp_str_to_i_strict (raises for non-numeric), matching Ruby semantics for the to_i method vs the Integer() kernel function. Also guard sp_str_to_i_strict against INTPTR_MIN (SP_INT_NIL sentinel collision), raising RangeError; update expected output accordingly.

Net: 427→434 pass, FAIL set unchanged (bigint_volatile_combo, bundle_class_13, bundle_classd_14, int_overflow_promote).

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
d963af260d92
Parent
ea3023ea299d

lib/sp_core.cmodifiedView file

@@ -151,6 +151,10 @@
151151 if (v < (long long)INTPTR_MIN || v > (long long)INTPTR_MAX)
152152 sp_raise_cls("RangeError", sp_sprintf("integer %lld out of range for 32-bit Integer", v));
153153 #endif
154+ /* INTPTR_MIN == SP_INT_NIL is the int-nil sentinel; that value cannot
155+ be represented as a Ruby Integer in Spinel. */
156+ if ((mrb_int)v == (mrb_int)INTPTR_MIN)
157+ sp_raise_cls("RangeError", sp_sprintf("integer %lld out of Spinel representable range", v));
154158 return (mrb_int)v;
155159 }
156160