Commit 027bd45b

027bd45bce55Merged

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

Description

Box a rescued exception when a local widens to poly

A local that starts nil and is later assigned a rescued exception widens to poly, but boxing an exception value was unsupported. Add a reserved SP_BUILTIN_EXCEPTION pointer-box id and route the boxed value's inspect / to_s / class through the exception helpers, so raised = e and a subsequent inspect work.

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

Details

Commit
027bd45bce55
Parent
de936a0b4a13

lib/sp_runtime.hmodifiedView file

@@ -2526,6 +2526,10 @@
25262526 #define SP_BUILTIN_RANGE (-10) /* sp_Range *, heap copy of stack-typed sp_Range when crossing into poly */
25272527 #define SP_BUILTIN_TIME (-11) /* sp_Time *, heap copy of stack-typed sp_Time when crossing into poly */
25282528 #define SP_BUILTIN_POLY_ARRAY (-12) /* sp_PolyArray *, array of sp_RbVal */
2529+#define SP_BUILTIN_EXCEPTION (-13) /* sp_Exception *, a rescued exception crossing into poly */
2530+struct sp_Exception_s;
2531+static const char *sp_exc_class_name(volatile struct sp_Exception_s *ve);
2532+static const char *sp_exc_message(volatile struct sp_Exception_s *ve);
25292533 /* Hash variant cls_ids — boxed into the cls_id of a poly slot so
25302534 Hash#dig can recover the concrete hash type at runtime. */
25312535 #define SP_BUILTIN_STR_INT_HASH (-13)
@@ -2803,6 +2807,7 @@
28032807 case SP_BUILTIN_PTR_ARRAY: return sp_PtrArray_inspect((sp_PtrArray *)v.v.p);
28042808 case SP_BUILTIN_RANGE: return sp_Range_inspect((sp_Range *)v.v.p);
28052809 case SP_BUILTIN_TIME: return sp_Time_inspect((sp_Time *)v.v.p);
2810+ case SP_BUILTIN_EXCEPTION: return sp_exc_message((volatile struct sp_Exception_s *)v.v.p);
28062811 default: return sp_str_empty;
28072812 }
28082813 default: return sp_str_empty;
@@ -2827,6 +2832,7 @@
28272832 case SP_BUILTIN_PTR_ARRAY: return SPL("Array");
28282833 case SP_BUILTIN_RANGE: return SPL("Range");
28292834 case SP_BUILTIN_TIME: return SPL("Time");
2835+ case SP_BUILTIN_EXCEPTION: return sp_exc_class_name((volatile struct sp_Exception_s *)v.v.p);
28302836 default: { sp_Class c = {v.cls_id}; return sp_class_to_s(c); }
28312837 }
28322838 default: return SPL("Object");
@@ -3321,6 +3327,7 @@
33213327 case SP_BUILTIN_POLY_ARRAY: return sp_PolyArray_inspect((sp_PolyArray *)v.v.p);
33223328 case SP_BUILTIN_RANGE: return sp_Range_inspect((sp_Range *)v.v.p);
33233329 case SP_BUILTIN_TIME: return sp_Time_inspect((sp_Time *)v.v.p);
3330+ case SP_BUILTIN_EXCEPTION: return sp_sprintf("#<%s: %s>", sp_exc_class_name((volatile struct sp_Exception_s *)v.v.p), sp_exc_message((volatile struct sp_Exception_s *)v.v.p));
33243331 default: return SPL("#<Object>");
33253332 }
33263333 default: return sp_str_empty;