Skip to content

Bug: Rust/Scala Lifetime & Symbol Parsing Error in _count_top_level_args #1852

Closed as not planned

Description

@squid-protocol

Bug: Rust/Scala Lifetime & Symbol Parsing Error in _count_top_level_args

Description

There is a silent attribute lookup failure in gitgalaxy/core/detector.py inside _count_top_level_args which causes Rust lifetimes (e.g., 'a) and Scala symbols (e.g., '_) to be misinterpreted as unclosed string literals.

In _count_top_level_args:

elif ch == "'":
    if getattr(self, "language", "") in ("rust", "scala") and re.match(
        r"[a-zA-Z_]\w*\b(?!')", body[i + 1 :]
    ):
        pass # It's a Rust lifetime or Scala symbol
    else:
        in_string = True
        quote_char = ch

The StructuralDetector class does not possess a language attribute; it uses self.primary_lang_id. Because getattr(self, "language", "") returns an empty string "", the language check always fails.

Impact

When a Rust or Scala file contains a lifetime parameter or symbol inside a function signature, the parser falls back to treating the ' as the start of a string literal. Because there is no closing ' quote, in_string remains True for the rest of the signature. Every top-level comma that follows is treated as being inside a string, hiding all subsequent arguments from the counter and causing severe undercounting.

Steps to Reproduce

  1. Run _count_top_level_args against a Rust function signature containing a lifetime: fn foo<'a>(x: &'a str, y: i32, z: i32)
  2. Observe that the returned argument count is 1 instead of 3, because y and z are swallowed by the supposed string literal starting at 'a.

Suggested Fix

Change getattr(self, "language", "") to getattr(self, "primary_lang_id", "").

Activity

  1. squid-protocol commented on Aug 18, 2026

    @squid-protocol
    OwnerAuthor

    Independent confirmation from the new tri-comparison tool (tests/tools/tri_comparison_chart.py, on feature/tri-comparison-audit), which cross-checks GitGalaxy's own extraction against tree-sitter and universal-ctags with neither treated as ground truth.

    Real corpus example matching this bug's exact shape — language-crucible/data/rust/bevy/bevy_ecs_table.rs::initialize:

    pub(crate) unsafe fn initialize(
        &mut self,
        row: TableRow,
        data: OwningPtr<'_>,
        tick: Tick,
        caller: MaybeLocation,
    ) {

    5 real parameters. Both tree-sitter and ctags independently report 5. GitGalaxy reports 3 — stops right after data: OwningPtr<'_>, i.e. exactly where a lifetime ('_) inside angle brackets would flip in_string = True and swallow every following top-level comma. Two independent tools agreeing against GitGalaxy on a real, unmodified file is strong corroborating evidence this is the same root cause described above, not a separate bug — the suggested fix (primary_lang_id instead of the never-populated language attribute) should very likely resolve this case too.

    Recorded in the new ledger at docs/self_scan/tri_comparison_ledger.json, shape rust/function/args/agree[ctags,tree_sitter]_vs[gitgalaxy] (21 occurrences total in the corpus, not just this one), for anyone verifying the fix against real-world data once it lands.

  2. added
    bug
    core-engine
    testing
    on Aug 19, 2026
  3. squid-protocol commented on Aug 20, 2026

    @squid-protocol
    OwnerAuthor

    Duplicate of #1872, which has the fuller writeup: independently confirmed root cause (self.language is never set anywhere in the class -- the real attribute is self.primary_lang_id), 4 concrete real-signature repro cases from bevy_ecs_world.rs/serde_core_de_mod.rs, and a follow-up comment documenting a second, related manifestation in _matching_paren_end (no lifetime guard at all, vs. this function's broken-but-present one). Closing this one as the duplicate since #1872 was filed with the fuller diagnosis already in hand -- all the detail here is preserved there.

  4. added
    duplicate
    on Aug 20, 2026
  5. added a commit that references this issue on Aug 20, 2026
    e7feb69
  6. 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-engineduplicatetesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions