Skip to content

csharp args: per-parameter attribute with doubly-nested parens breaks the parameter-list capture's 1-level nesting limit #2237

Closed

Description

@squid-protocol

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

Confirmed real GitGalaxy defect, currently reproducing. Two functions in roslyn/LanguageParser.cs are undercounted:

private void ParseNamespaceBody(
    [NotNullIfNotNull(nameof(openBraceOrSemicolon))] ref SyntaxToken? openBraceOrSemicolon,
    ref NamespaceBodyBuilder body,
    ref SyntaxListBuilder? initialBadNodes,
    SyntaxKind parentKind)

(line 410, 4 real parameters) and ParseNamespaceBodyWorker (line 562, 5 real parameters, same shape plus one more).

GitGalaxy reports args=2 for both; tree-sitter correctly reports 4 and 5.

Root cause: the C# args rule's parameter-list capture ((\((?:[^()]|\([^()]*\))*\))) only tolerates ONE level of paren nesting. The first parameter here carries a per-parameter attribute with TWO levels of nesting — [NotNullIfNotNull(nameof(openBraceOrSemicolon))] — so the capture fails to match the real parameter list and falls through to a wrong match elsewhere. Confirmed in isolation: the regex fails against the signature with the attribute present, and succeeds once the attribute is stripped.

Note: ctags also produces zero tags for either function on this exact construct (confirmed via a direct ctags --output-format=json run) — a separate, pre-existing ctags limitation on this file, not corroborating either reading.

This is a fourth, narrower mechanism than the three issue #2051 already fixed (tuple returns, capture-group truncation on tuple params, missing generic-stepper) — #2051's fix didn't address per-parameter-attribute nesting depth.

Suggested fix: extend the args capture's nesting tolerance to at least 2 levels (matching whatever func_start's own return-type/annotation handling already tolerates, if it does), or special-case per-parameter attributes the way other languages special-case similar prefixes.

Activity

  1. added
    bug
    core-engine
    threat: false-negative
    on Aug 26, 2026
  2. 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