Commit eaefc161
eaefc1614fdaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): regex const initialised with .freeze resolves through to the pattern
Fixes #394.
PATTERN = /pat/.freeze wraps the literal in a .freeze CallNode
in Prism. find_regexp_index walked @const_expr_ids looking for a
RegularExpressionNode and missed the wrapper, so gsub(PATTERN, ...)
fell through to sp_str_gsub(... cst_PATTERN ...) (a mrb_int arg
into a const char * slot — fails C-compile under -Werror).
Fix: peel the .freeze CallNode wrapper off @const_expr_ids[ci]
before checking for RegularExpressionNode. The RX = /pat/ form
without .freeze already worked.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- eaefc1614fda
- Parent
- f5f0efa6cd70
spinel_codegen.rbmodifiedView file
# underlying pattern, so `RX = /pat/; RX.match?(s)` and # `s =~ RX` dispatch to the engine instead of falling through # to the literal-`(-1)` / `sp_str_include` fallbacks. # Also unwrap `.freeze` (`PATTERN = /pat/.freeze`) — Prism wraps # the literal in a `freeze` CallNode whose receiver is the # RegularExpressionNode. Issue #394. if @nd_type[nid] == "ConstantReadNode" cname = resolve_const_ref_name(nid) if cname != "" ci = find_const_idx(cname) if ci >= 0 && ci < @const_expr_ids.length eid = @const_expr_ids[ci] if eid >= 0 && @nd_type[eid] == "CallNode" && @nd_name[eid] == "freeze" recv_freeze = @nd_receiver[eid] if recv_freeze >= 0 eid = recv_freeze end end if eid >= 0 && @nd_type[eid] == "RegularExpressionNode" return find_regexp_index(eid) endtest/regex_const_freeze.rbaddedView file
Loading diff…
test/regex_const_freeze.rb.expectedaddedView file
Loading diff…