Skip to content

csharp args regex was never updated for tuple return types / generic methods / nested-paren params, unlike its func_start sibling #2051

Closed

Description

@squid-protocol

Summary

func_start's regex was hardened over several past issues to support C#'s tuple return types
((int, string) Foo(...)), generic method type parameters (Method<T>(...)), and complex nested
generics. The sibling args rule (gitgalaxy/standards/language_standards.py, "csharp" block,
"args": re.compile(...)) was never given the equivalent treatment — it silently mismatches or
mis-truncates on exactly these same shapes, which are extremely common in modern C# (tuples and
generic methods are idiomatic, not edge cases). Confirmed via three distinct, independently
reproduced mechanisms while investigating tri_comparison_ledger.json's csharp args-count
shapes.

Mechanism 1: tuple/generic-wrapped-tuple return types don't match Branch 1 at all

Branch 1's return-type-loop character class is [\w<>\[\]?,.*] — no parens, unlike func_start's
equivalent loop ([a-zA-Z0-9_<>\[\]?,.()*], which explicitly supports tuples per its own
comments). A tuple-shaped or generic-wrapped-tuple return type immediately before the method name
means the walk can never consume it, so the whole Branch 1 alternative fails to match.

Confirmed via direct regex testing, isolated from the pipeline:

rx = LANGUAGE_DEFINITIONS["csharp"]["rules"]["args"]
rx.search("internal (bool IsCandidate, bool IsTaskLike) HasEntryPointSignature(MethodSymbol method, BindingDiagnosticBag bag)\n{\n")
# -> None (real signature: 2 params; DB reports 0)

Real-corpus occurrences (roslyn/CSharpCompilation.cs, roslyn/Workspace.cs), all confirmed by
reading the actual source and counting real parameters:

  • HasEntryPointSignature (line 2310): real=2, GitGalaxy reports 0.
  • SetCurrentSolutionEx (line 181, (Solution oldSolution, Solution newSolution) tuple return):
    real=1, GitGalaxy reports 2 (falls through to a different branch that produces a wrong count
    rather than 0 here — the failure mode isn't always "0", just "wrong").
  • SetCurrentSolution (line 230, same tuple-return shape): real=4, GitGalaxy reports 0.
  • SetCurrentSolution<TData> (line 444): real=5, GitGalaxy reports 2.
  • SetCurrentSolutionAsync (line 249, ValueTask<(bool updated, Solution newSolution)> —
    generic-wrapped tuple): real=6, GitGalaxy reports 2.
  • SetCurrentSolutionAsync<TData> (line 466): real=7, GitGalaxy reports 0.

Mechanism 2: the args capture group truncates at the first unbalanced ), breaking on any tuple-typed PARAMETER (independent of return type)

All three branches share the same capture: (\([^)]*\)) — a naive non-nested paren match. A
parameter whose own type contains parens (a tuple-typed parameter, or a generic wrapping one)
truncates the match at the first ) found, which can be deep inside the first parameter's own
type, well before the real closing paren of the parameter list.

Confirmed via direct regex testing:

rx.search("public bool Equals((ImmutableArray<byte> ContentHash, int Position) x, (ImmutableArray<byte> ContentHash, int Position) y)\n{\n")
# captured args span: '((ImmutableArray<byte> ContentHash, int Position)' -- truncated after the
# FIRST tuple param's own closing paren, the second param and the real closing paren never seen
  • Equals (roslyn/CSharpCompilation.cs:2539, two tuple-typed params): real=2, GitGalaxy reports 1.
  • ProcessEventHandlerWorkQueueAsync (roslyn/Workspace.cs:705, first param
    ImmutableSegmentedList<(EventArgs Args, EventHandlerSet HandlerSet)> list): real=2, GitGalaxy
    reports 1 (same truncation shape, confirmed via the same isolated regex test).

Mechanism 3: no generic-type-parameter stepper on the method name, unlike func_start

func_start's name capture already has (?:[ \t\n]*<[^>]{0,100}>)?[ \t\n]{0,200}\( — a "generic
stepper" that skips a method-level <T>/<TData>/<TArg> before the real opening paren. args's
name capture is bare \w+[ \t\n]*(\([^)]*\)) with no equivalent — a generic method's <...>
between the name and its real parameter list means the whole pattern fails to match.

Confirmed via direct regex testing:

rx.search("private void OnAnyDocumentTextChanged<TArg>(\n    DocumentId documentId,\n    ...\n)\n{\n")
# -> None (real signature: 7 params; DB reports 2 -- falls through to a wrong-branch match
#    elsewhere, same "wrong, not just missing" failure mode as mechanism 1)
  • OnAnyDocumentTextChanged<TArg> (roslyn/Workspace.cs:1248): real=7, GitGalaxy reports 2.

Scope

7 of the tri_comparison_ledger.json shape occurrences investigated trace to mechanism 1, 2
trace to mechanism 2, 1 traces to mechanism 3 (10 of the ~13 total args-shape occurrences in the
current corpus sample). Given tuples and generic methods are idiomatic in any modern C# 7+
codebase (not a rare construct), this is likely a meaningful undercounting pattern in production
scans generally, not just this corpus.

Two ledger shapes originally suspected to be GitGalaxy bugs turned out NOT to be, on closer
inspection — noted here so they aren't re-investigated:

  • GetModifierExcludingScoped's two overloads (1 param and 2 params respectively) are BOTH
    correctly counted by GitGalaxy; the ledger's apparent mismatch (ctags=2, gitgalaxy=1, tree_sitter=1) is a rank-based-pairing artifact from the reconciler comparing occurrences by
    position rather than by which overload they actually are — not a real disagreement.
  • GetHashCode's tuple-parameter overload (roslyn/CSharpCompilation.cs:2544) is correctly
    counted by GitGalaxy (1) and tree-sitter (1); ctags reports 2, mis-splitting the tuple-typed
    parameter's own internal comma as if it were a second top-level parameter — a confirmed
    ctags-side limitation, not a GitGalaxy defect (documented in tests/tools/ctags_reader.py's
    csharp KIND MAPS bullet as the same family as the existing tuple-related ctags notes there).

Suggested fix direction

Not attempted here — this needs real design work across three separate regex mechanisms plus
full corpus verification, not a quick patch:

  1. Extend Branch 1/2/3's return-type-loop and/or add an explicit tuple-return-type allowance,
    mirroring func_start's already-working character class.
  2. Replace the naive (\([^)]*\)) capture with something that tolerates one level of nested
    balanced parens (similar direction to csharp func_start: return-type loop swallows call-expression fragments as fake return types #2035's fix for func_start's own return-type loop,
    though this is a different position in the pattern).
  3. Add the same generic-stepper func_start already has to the name-capture position(s).

Given args is used by every C#-scanning consumer of the engine (risk scoring, coupling metrics),
whoever picks this up should run the full differential-scan protocol (extraction gauntlet + strict
tests, both golden masters re-blessed, crucible_check.py against the full ~80-repo corpus) per
CLAUDE.md, not just a local spot check on these specific corpus files.

Found via the tri-comparison-ledger-sweep skill's csharp pass.

Activity

  1. added
    bug
    on Aug 21, 2026
  2. added 7 commits that reference this issue on Aug 21, 2026
  3. added
    core-engine
    threat: false-negative
    on Aug 26, 2026
  4. 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-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions