Commit 01011f53
01011f532228Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(analyze,codegen): reject Regexp.new flag-arg form so divergence is loud
Tighten regexp_new_literal_pattern to require exactly one argument
(no block, no kwargs) before folding into the static pattern table.
Without this, Regexp.new("foo", Regexp::IGNORECASE) would have
matched the 1-arg literal arm and silently dropped the flag --
spinel positions itself as a Ruby subset, so a supported method
diverging from CRuby semantics on the same input is a bug, not a
quirk to document.
The 2-arg form now falls through to warn_unresolved_call (loud)
exactly as it did before the literal-arg fix landed, so callers
get the prior diagnostic instead of a silent wrong answer.
Refs #586
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 01011f532228
- Parent
- dbcaa07220c3
spinel_analyze.rbmodifiedView file
end # Returns the literal source string when `nid` is a `Regexp.new("...")` # (or `Regexp.compile("...")`) call with a single StringNode argument, # "" otherwise. Lets `pattern = Regexp.new("foo")` fold into the same # static pattern table as `pattern = /foo/`, so `pattern.match?(s)` # dispatches through `sp_re_pat_<i>` instead of falling through to # unresolved-call. Dynamic-arg forms return "" and fall back. # (or `Regexp.compile("...")`) call with exactly one StringNode # argument, "" otherwise. Lets `pattern = Regexp.new("foo")` fold # into the same static pattern table as `pattern = /foo/`, so # `pattern.match?(s)` dispatches through `sp_re_pat_<i>` instead of # falling through to unresolved-call. Dynamic-arg forms return "" # and fall back. # # The arity check is strict (exactly 1 arg, no kwargs, no block) so # `Regexp.new("foo", Regexp::IGNORECASE)` falls through to the loud # `warn_unresolved_call` path instead of silently dropping the flag # -- silent CRuby divergence on a supported method belongs in the # bug bucket, not the quirk bucket. def regexp_new_literal_pattern(nid) if @nd_type[nid] != "CallNode" return "" if mn != "new" && mn != "compile" return "" end if @nd_block[nid] >= 0 return "" end recv = @nd_receiver[nid] if recv < 0 return "" return "" end arg_ids = get_args(args_id) if arg_ids.length == 0 if arg_ids.length != 1 return "" end a0 = arg_ids[0]spinel_codegen.rbmodifiedView file
Loading diff…