Commit 2d82efaf

2d82efaf07a9Merged

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

Description

Regexp#source and #options on a regex literal

Both are compile-time constants of the literal: source is the unescaped pattern string; options maps the Prism i/x/m flag bits to Ruby's IGNORECASE/EXTENDED/MULTILINE option integer.

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

Details

Commit
2d82efaf07a9
Parent
d053fab37953

src/analyze.cmodifiedView file

@@ -726,6 +726,11 @@
726726 if ((rrt && !strcmp(rrt, "RegularExpressionNode")) ||
727727 (art && !strcmp(art, "RegularExpressionNode"))) return TY_POLY;
728728 }
729+ /* /re/.source -> String, /re/.options -> Integer (compile-time constants) */
730+ if (recv >= 0 && argc == 0 && nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "RegularExpressionNode")) {
731+ if (!strcmp(name, "source")) return TY_STRING;
732+ if (!strcmp(name, "options")) return TY_INT;
733+ }
729734
730735 if (recv >= 0 && argc == 1 && is_arith_op(name)) {
731736 if (rt == TY_STRING) {