Commit 5b711b99

5b711b99290cMerged

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

Description

codegen(promote): name the operand class in the regex =~ non-String TypeError

/re/ =~ x with a non-String x raises TypeError. The statically-typed path bakes the operand's class into the message ("...of Integer into String"), but the poly path (x widened under promote) raised a generic "no implicit conversion into String" with no class name. Route the poly runtime check through a new sp_raise_no_str_conversion helper that names the value's actual class via sp_poly_class_name.

Fixes promote-mode regex_match_nonstring.

Default test 992/0/0 and optcarrot checksum 59662 unchanged.

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

Details

Commit
5b711b99290c
Parent
16d5b8d94593

lib/sp_runtime.hmodifiedView file

@@ -3311,6 +3311,14 @@
33113311 default: return SPL("Object");
33123312 }
33133313 }
3314+/* Raise TypeError "no implicit conversion of <class> into String" for a poly
3315+ value, naming its actual runtime class (the statically-typed path bakes the
3316+ class name into a literal; the poly path resolves it here). */
3317+SP_NORETURN SP_COLD static void sp_raise_no_str_conversion(sp_RbVal v) {
3318+ static char buf[128];
3319+ snprintf(buf, sizeof buf, "no implicit conversion of %s into String", sp_poly_class_name(v));
3320+ sp_raise_cls("TypeError", buf);
3321+}
33143322 typedef struct { sp_RbVal *data; mrb_int len; mrb_int cap; mrb_int frozen; } sp_PolyArray;
33153323 static mrb_bool sp_PolyArray_eq(sp_PolyArray *a, sp_PolyArray *b);
33163324 static mrb_float sp_poly_to_f(sp_RbVal v); /* defined below; used by the bigint+float arms */