Commit 66b013c4
66b013c463c5Merged
Ori Pekelman <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: resolve a regex held in a namespaced constant (M::RE)
find_regexp_index's constant arm gated on ConstantReadNode only, so a
namespaced constant regex (M::RE) fell through to the fallbacks: a
s.gsub(M::RE, ...) silently no-op'd (returned the receiver unchanged)
and s.scan(M::RE) raised undefined method 'scan' for string.
resolve_const_ref_name already maps M::RE to the registered constant
name M_RE, so widening the gate to also accept ConstantPathNode
forwards it through the same static pattern table as a top-level
constant. =~ / match / sub / split share the path via regex_pat_c_expr.
Adds test/regex_namespaced_const.rb (incl. a nested A::B::WS.freeze case).
Closes #1008
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 66b013c463c5
- Parent
- 7780fff2c6e8
spinel_codegen.rbmodifiedView file
# Also unwrap `.freeze` (`PATTERN = /pat/.freeze`) — Prism wraps # the literal in a `freeze` CallNode whose receiver is the # RegularExpressionNode. . if @nd_type[nid] == "ConstantReadNode" # ConstantPathNode (`M::RX`) resolves the same way — resolve_const_ref_name # already maps `M::RX` to the registered name `M_RX`. Without this, a # namespaced constant regex fell through, so `s.gsub(M::RX, ...)` silently # no-op'd and `s.scan(M::RX)` raised undefined-method (e.g. emoji_regex). if @nd_type[nid] == "ConstantReadNode" || @nd_type[nid] == "ConstantPathNode" cname = resolve_const_ref_name(nid) if cname != "" ci = find_const_idx(cname)test/regex_namespaced_const.rbaddedView file
Loading diff…
test/regex_namespaced_const.rb.expectedaddedView file
Loading diff…