Repository navigation
Ruby: methods no longer run to the end of the file after a keyword inside a literal - #3736
Merged
Merged
Conversation
…al (#3646) Three ways a keyword or delimiter inside a literal broke Mode-D `def`/`end` pairing, each running a method to the end of its file and handing it the next methods' calls: - `/.../` regex literals were never shielded, so `class` in `/<p\s+class="footnote"/` (rails generator.rb) or `if` in `x =~ /if|do/` opened a scope. `_apply_literal_shield` blanks a ruby regex opened in value position (line start, after `( , = ~ ! & | { [ ; ? :` or an expression keyword); division never is one. The issue's guess (a quote inside the regex) was not the trigger. - prism took the `#` of `#{...}` inside `%r{^https?://#{DOMAIN}/}o` for a comment, cut the line, and the `"` after it opened a multi-line string (brew download_strategy.rb `fetch`). Ruby's `#` delimiter skips `#{`. - `@module = T.let(` counted `module` as an opener. ruby's opener/closer lookbehind now excludes the `@`/`$` sigils. call_graph_accuracy (ruby): precision 92.7% -> 100.0% (FP 73 -> 0), recall 92.9% -> 93.8%. Goldens: download_strategy.rb, brew.rb, generator.rb and their aggregates, plus the corpus-wide XYZ re-solve. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3646 (part of #3641). The Ruby slicer (Mode D) pairs
def/class/if/dowithend. Three kinds of literal leaked a keyword or a delimiter into that count. Each one made a method run to the end of its file and take the following methods' calls: theruby/call/outside-ts-functionshape, 73 false positives./…/regex literals were never shielded.extract_anchorsin rails'generator.rbhashtml.scan(/<p\s+class="footnote"\s+id="([^"]+)/). Theclassinside the regex opened a scope that noendclosed. The issue guessed the unbalanced"was the trigger; bisecting showed it's the keyword, and the quote is harmless.x =~ /if|while|do/breaks the same way._apply_literal_shieldhas a Ruby regex branch in its single atomic pass, so a string or comment that starts earlier still claims its span./opens a regex only in value position: at line start, after( , = ~ ! & | { [ ; ? :, or after an expression keyword (when,if,unless,return, …). Division (a / b,x/2,reduce(:/)) is never one.[…]class may contain/, and escapes are atomic.\1backreference keeps its group number.#{inside%r{…}. Fixing (1) exposed a second runaway in brew'sdownload_strategy.rb, infetch, which it had been hiding. Line 475 isurl.sub(%r{^https?://#{GitHubPackages::URL_DOMAIN}/}o, "#{domain.chomp("/")}/"). prism's line masker shields only quoted strings, so it read the#of that#{as a comment and cut the line. The"that followed was left open, and because Ruby strings may span lines, it swallowed everyendbelow.#comment delimiter is now#(?!\{). Outside a recognised string,#{in Ruby is an interpolation in a literal prism doesn't model, never a comment. Real comments,# {hash}included, are unaffected.@module = T.let(countedmoduleas an opener (CVSDownloadStrategy#initializeran to EOF).@and$sigils as well as:and..@module,@classand$endare variable names, never keywords.tests/dead_key_audit.pyallowlists the new regex group namerx, like the existingheredoc/commententries.Type of change
gitgalaxy/core/detector.py,language_standards.py,prism.py, or a per-language rule)CI checklist
python tests/tools/audit_check.pypasses (bundles the ruff/mypy/dead-key baseline-gated audits +ruff format --check)python -m pytest tests/passespython tests/tools/crucible_check.pypasses: both fixtures re-blessed; see belowpython tests/tools/tree_sitter_accuracy_audit.py --all --cipasses: 30 languages, all OKMeasurements
call_graph_accuracy.py(Level 1, against tree-sitter), on language-crucible v1.5.0:No other language moved. The baseline is regenerated. The 64 misses left are calls inside string interpolation (
"#{self.class.name}"), which the engine blanks as literal content (C7).Fix (1) alone briefly read as a regression (92.1%), because it made
fetchvisible and so exposed runaway (2). That's why (2) and (3) are in this PR.Golden masters, scoped diff: 235 differences.
shell/brew/download_strategy.rb,shell/brew/brew.rbandruby/rails/generator.rb. What moves there is magnitude, LOC, branches, the exposures, function analysis and archetypes.shell/brewandruby/railsdirectory totals, Ruby's composition, the archetype distribution,total_loc(+54, the lines prism used to cut at#{now count as code), andavg_tech_debtin the fourth decimal.keyword-rosetta:
rosetta_audit.pyfinds 51 languages, 0 regressions.Differential Scan target
language-crucible
ruby/rails/generator.rb,shell/brew/download_strategy.rb.Verification
New test file:
tests/extraction/languages/test_ruby_regex_literal_3646.py. It covers:%r{…#{…}…}shape through prism, and a real#comment staying a comment;@module/$endvariables;🤖 Generated with Claude Code
https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Generated by Claude Code