Skip to content

ruby args regex: do|...|/{|...|} block-parameter fallback isn't scoped to define_method, misattributes an unrelated iterator block inside a paren-less def's body #2241

Closed

Description

@squid-protocol

Found during a tri-comparison ledger sweep of ruby/function/args/agree[none]_vs[gitgalaxy,tree_sitter].

Confirmed real, currently-reproducing GitGalaxy defect — 6 of 9 sampled occurrences.

gitgalaxy/standards/language_standards.py's ruby args rule has 4 alternatives in one pattern: a real def name(...) parameter list, OR a do |...| block, OR a { |...| } block, OR a -> (...) lambda — intended so define_method(:x) do |a,b| ... end (no def(...) at all) still gets a real arg count. But the match isn't scoped to require the block be the method's own define_method-style body; it's found via a search/finditer over the whole method body, so it matches the first unrelated enumerator block deep inside a normal, paren-less def and misattributes that block's own parameter as the method's own argument count.

Confirmed examples (all in rails/*.rb), each a genuinely zero-argument method whose body happens to contain an ordinary iterator block:

def touch_attachments
  attachments.then do |relation|   # <- GitGalaxy reads this as touch_attachments' own arg (=1)
    ...
def add_digests
  assets_files.each do |asset|     # <- same misattribution
    ...

Also affects: mail, generate_guides, guides_to_generate, copy_assets. tree-sitter and ctags both correctly report 0 args for all six; GitGalaxy alone reports 1.

Suggested fix: scope the do|...|/{|...|} fallback alternative so it only matches when the block is the method's own body-opening construct (e.g. immediately following the method name with no def/parens at all — the actual define_method(:x) do |...| shape), not any block found anywhere inside an already-def-declared method's body.

Activity

  1. added
    bug
    core-engine
    threat: false-positive
    on Aug 26, 2026
  2. added a commit that references this issue on Aug 26, 2026
    d914281
  3. added this to the v2.4.9 milestone on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginethreat: false-positive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions