Commit 101c0077
101c0077d3e1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Fix poly argument to Regexp.escape and regex match? in narrowed context
When a poly local is passed to Regexp.escape or used in a regex match? call, unbox via sp_poly_to_s() instead of passing the raw sp_RbVal. Fixes compilation failures for is_a?(String)-narrowed locals.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 101c0077d3e1
- Parent
- 87ff5492ae57
src/codegen.cmodifiedView file
@@ -3177,7 +3177,9 @@
31773177
(!strcmp(name, "escape") || !strcmp(name, "quote")) &&31783178
nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "ConstantReadNode") &&31793179
nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "Regexp")) {3180-
buf_puts(b, "sp_re_escape("); emit_expr(c, argv[0], b); buf_puts(b, ")");3180+
TyKind _re_at = comp_ntype(c, argv[0]);3181+
if (_re_at == TY_POLY) { buf_puts(b, "sp_re_escape(sp_poly_to_s("); emit_expr(c, argv[0], b); buf_puts(b, "))"); }3182+
else { buf_puts(b, "sp_re_escape("); emit_expr(c, argv[0], b); buf_puts(b, ")"); }31813183
return;31823184
}31833185
@@ -3891,7 +3893,8 @@
38913893
int rre = re_lit_index(c, recv);38923894
if (rre >= 0 && (!strcmp(name, "match?") || !strcmp(name, "===")) && argc == 1) {38933895
/* /re/ === str and /re/.match?(str) both yield a match boolean */3894-
buf_printf(b, "sp_re_match_p(sp_re_pat_%d, ", rre); emit_expr(c, argv[0], b); buf_puts(b, ")");3896+
if (a0 == TY_POLY) { buf_printf(b, "sp_re_match_p(sp_re_pat_%d, sp_poly_to_s(", rre); emit_expr(c, argv[0], b); buf_puts(b, "))"); }3897+
else { buf_printf(b, "sp_re_match_p(sp_re_pat_%d, ", rre); emit_expr(c, argv[0], b); buf_puts(b, ")"); }38953898
return;38963899
}38973900
if (rre >= 0 && !strcmp(name, "match?") && argc == 2) {@@ -4008,7 +4011,8 @@
40084011
}40094012
if (rp_ok && rp.p) {40104013
if ((!strcmp(name, "match?") || !strcmp(name, "===")) && argc == 1) {4011-
buf_printf(b, "sp_re_match_p(%s, ", rp.p); emit_expr(c, argv[0], b); buf_puts(b, ")");4014+
if (a0 == TY_POLY) { buf_printf(b, "sp_re_match_p(%s, sp_poly_to_s(", rp.p); emit_expr(c, argv[0], b); buf_puts(b, "))"); }4015+
else { buf_printf(b, "sp_re_match_p(%s, ", rp.p); emit_expr(c, argv[0], b); buf_puts(b, ")"); }40124016
free(rp.p); return;40134017
}40144018
if (!strcmp(name, "=~") && argc == 1) {