Commit 77d8644c
77d8644c6385Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Regexp.compile alias, regex match globals as GlobalVariableReadNode, const/inline Regexp.new as pattern arg
- Add Regexp.compile as alias for Regexp.new in analyze/codegen
- Handle $~ $& $` $' $+ as GlobalVariableReadNode (Prism parses them this way in some contexts) in both infer_type and emit
- Extend is_regex_lv_arg to accept ConstantReadNode (not just LocalVariableReadNode)
so
str =~ REGEX_CONSTis handled - Fix fallback in both arg/recv regex pattern paths: emit_expr into a separate buffer first so Regexp.new pre-code lands before the mrb_regexp_pattern* declaration, not inside it (invalid C previously)
Fixes regexp_new_literal test (134 ERR).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 77d8644c6385
- Parent
- 442ee85e4e06
src/analyze.cmodifiedView file
@@ -541,6 +541,15 @@
541541
}542542
}543543
544+
/* Regexp.compile is an alias for Regexp.new */545+
if (recv >= 0 && !strcmp(name, "compile")) {546+
const char *rty = nt_type(nt, recv);547+
if (rty && !strcmp(rty, "ConstantReadNode")) {548+
const char *cn = nt_str(nt, recv, "name");549+
if (cn && !strcmp(cn, "Regexp")) return TY_REGEX;550+
}551+
}552+
544553
/* StringScanner instance methods */545554
if (recv >= 0 && rt == TY_STRINGSCANNER) {546555
if (!strcmp(name, "scan") || !strcmp(name, "check") || !strcmp(name, "scan_until") ||@@ -1910,6 +1919,9 @@
19101919
if (nm && !strcmp(nm, "$?")) return TY_INT; /* last child exit status */19111920
if (nm && (!strcmp(nm, "$PROGRAM_NAME") || !strcmp(nm, "$0"))) return TY_STRING;19121921
if (nm && (!strcmp(nm, "$!") || !strcmp(nm, "$;") || !strcmp(nm, "$,"))) return TY_NIL;1922+
/* regex match globals: nullable strings ($~ == $&, $`, $', $+) */1923+
if (nm && (!strcmp(nm, "$~") || !strcmp(nm, "$&") || !strcmp(nm, "$`") ||1924+
!strcmp(nm, "$'") || !strcmp(nm, "$+"))) return TY_STRING;19131925
const char *rn = nm ? comp_resolve_gvar(c, nm + 1) : NULL;19141926
LocalVar *lv = rn ? comp_gvar(c, rn) : NULL;19151927
return lv ? lv->type : TY_UNKNOWN;src/codegen.cmodifiedView file
Loading diff…