Commit 5c3b0ec6
5c3b0ec641a4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Reject aliasing of regexp special globals with a clear diagnostic
alias $MATCH $& (and the other English aliases of $`, $', $+, $~) fell
through to an undeclared generated C symbol (gv__amp) and failed the C
build. Spinel lowers direct reads of the match globals to special regexp
runtime accessors, not ordinary global storage, so aliasing them is
outside the AOT subset. Detect the shape in the analyzer and fail with
"global aliasing of regexp special globals is not supported" instead of
emitting broken C. Documented in docs/INCOMPATIBILITIES.md.
Closes #1307
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 5c3b0ec641a4
- Parent
- 4c7768be47c0
docs/INCOMPATIBILITIES.mdmodifiedView file
@@ -53,6 +53,32 @@
5353
supported. For codepoint- or byte-level iteration, use the supported5454
`String#chars`, `#each_char`, `#codepoints`, or `#bytes`.5555
56+
## Aliasing the regexp match globals57+
58+
CRuby's `English` library aliases the punctuation match globals to readable59+
names:60+
61+
```ruby62+
require "English" # alias $MATCH $&, alias $PREMATCH $`, ...63+
"hello world" =~ /\w+/64+
puts $MATCH # => "hello"65+
```66+
67+
In Spinel the match globals (`$&`, `` $` ``, `$'`, `$+`, `$~`) are not ordinary68+
global-variable storage: a direct read lowers to a special regexp runtime69+
accessor. Supporting `alias $name $&` would require a separate special-global70+
alias mechanism plus broader `MatchData` compatibility, which is outside the71+
intended AOT subset. Aliasing one of these globals is rejected at compile time72+
rather than falling through to an undefined generated symbol:73+
74+
```75+
$ spinel uses_english.rb76+
Error: global aliasing of regexp special globals is not supported (alias $MATCH $&)77+
```78+
79+
Direct reads of the match globals work as usual; only aliasing them is80+
unsupported. `require "English"` therefore does not compile.81+
5682
## Flip-flop operator5783
5884
CRuby supports the flip-flop operator (a `Range` used as a condition, toggledspinel_analyze.rbmodifiedView file
Loading diff…