Commit 13c7b7e1
13c7b7e1c797Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Regex =~ on a string operand
str =~ /re/ and /re/ =~ str lower to sp_re_match_poly, returning the match offset or nil (a poly value); the analyzer types =~ as poly when either operand is a regex literal. Guarded on the non-regex operand being a string so a non-String operand still falls through (TypeError path is a follow-up). Exercises the engine's \h \H \D \W \S shorthands.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 13c7b7e1c797
- Parent
- 0be20b62343a
src/analyze.cmodifiedView file
@@ -622,6 +622,11 @@
622622
if (!strcmp(name, "!")) return TY_BOOL;623623
if (!strcmp(name, "respond_to?") && recv >= 0) return TY_BOOL;624624
if ((!strcmp(name, "match?") || !strcmp(name, "!~")) && recv >= 0) return TY_BOOL;625+
if (!strcmp(name, "=~") && recv >= 0 && argc == 1) {626+
const char *rrt = nt_type(nt, recv), *art = nt_type(nt, argv[0]);627+
if ((rrt && !strcmp(rrt, "RegularExpressionNode")) ||628+
(art && !strcmp(art, "RegularExpressionNode"))) return TY_POLY;629+
}625630
626631
if (recv >= 0 && argc == 1 && is_arith_op(name)) {627632
if (rt == TY_STRING) {src/codegen.cmodifiedView file
Loading diff…