Commit cd284e6f
cd284e6f8dd2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
String#gsub/sub with a regex literal on a poly receiver
A poly-typed receiver (sp_RbVal, e.g. a sym_poly_hash lookup that is a string at runtime) reaching gsub/sub fell through to the NoMethodError gate. Add a poly arm that extracts the string payload via sp_poly_to_s and routes a regex-literal pattern to the engine, mirroring the TY_STRING receiver path, and report the result as a string from analyze. The constant-regex form (PATTERN = /.../.freeze) still needs literal resolution and is left for separate work.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- cd284e6f8dd2
- Parent
- 4f60232ce6ba
src/analyze.cmodifiedView file
@@ -591,6 +591,7 @@
591591
return TY_BOOL;592592
if (rt == TY_POLY) {593593
if (!strcmp(name, "to_s") || !strcmp(name, "inspect")) return TY_STRING;594+
if ((!strcmp(name, "gsub") || !strcmp(name, "sub")) && argc == 2) return TY_STRING;594595
if (!strcmp(name, "to_i") || !strcmp(name, "length") || !strcmp(name, "size")) return TY_INT;595596
if (!strcmp(name, "to_f")) return TY_FLOAT;596597
/* poly method dispatch: unify the return type over every class thatsrc/codegen.cmodifiedView file
Loading diff…