Skip to content

csharp func_start: two more call-expression false positives surviving #2035's fix #2054

Closed

Description

@squid-protocol

Summary

Investigating a fresh, uncapped tri-comparison diff after #2035/#2036 merged (via
gather_language("csharp"), not the ledger's capped example sample), found 2 more confirmed
func_start false positives on real Roslyn source that #2035's fix does NOT cover — both in
roslyn/LanguageParser.cs, both call-expressions inside multi-line/switch-expression contexts,
same general shape as #2035 (a receiver.Method( call mistaken for a declaration) but via two
different specific mechanisms.

Case 1: ref (a real modifier keyword) appearing as a call-argument prefix, not a declaration modifier

roslyn/CSharpCompilation.cs:1885 (adjacent occurrence, exact line reported varies slightly by
match position):

symbol = new MissingMetadataTypeSymbol.TopLevel(
    new MissingAssemblySymbol(AssemblyIdentity.FromAssemblyDefinition(HostObjectType.GetTypeInfo().Assembly)).Modules[0],
    ref mdName,
    SpecialType.None,
    CreateReflectionTypeNotFoundError(HostObjectType));

ref is a legitimate Branch A modifier keyword (ref int x parameter declarations are real), but
here it's being used as a call-argument pass-by-reference prefix (ref mdName), not a declaration
modifier. The regex can't currently distinguish the two contexts, so it captures
CreateReflectionTypeNotFoundError as a phantom function name. Reproduced standalone:

rx = LANGUAGE_DEFINITIONS["csharp"]["rules"]["func_start"]
rx.finditer("""
    symbol = new MissingMetadataTypeSymbol.TopLevel(
        new MissingAssemblySymbol(AssemblyIdentity.FromAssemblyDefinition(HostObjectType.GetTypeInfo().Assembly)).Modules[0],
        ref mdName,
        SpecialType.None,
        CreateReflectionTypeNotFoundError(HostObjectType));
    }
""")
# -> matches 'ref mdName,\n...\nCreateReflectionTypeNotFoundError(' as group 1

The real CreateReflectionTypeNotFoundError declaration exists at CSharpCompilation.cs:1855
and is found correctly elsewhere — this is a phantom SECOND occurrence, not a missed real one.

Case 2: a ternary ? operator consumed by the return-type loop as a nullable-type marker

roslyn/LanguageParser.cs:2336, inside a switch expression:

SyntaxKind.DelegateKeyword =>
    PeekToken(1).Kind == SyntaxKind.AsteriskToken
        ? _syntaxFactory.TypeConstraint(this.ParseType())
        : _syntaxFactory.TypeConstraint(AddTrailingSkippedSyntax(
            this.AddError(this.CreateMissingIdentifierName(), ErrorCode.ERR_NoDelegateConstraint),
            this.EatToken())),

_ => parseTypeOrAllowsConstraint(),

The return-type-loop's per-token character class (already touched by #2035's fix) includes ?
literally (intended for nullable-type suffixes like string?). Here the ternary operator's ?
gets consumed as if it were a nullable-type marker, letting the walk continue past it and capture
_syntaxFactory.TypeConstraint as the phantom function name. Reproduced standalone (same snippet
as above) — groups() shows Branch B's capture (match.lastindex == 2) is _syntaxFactory.TypeConstraint.
Note this.EatToken at line 2339 in the same snippet, which #2035 already fixed, no longer
reproduces here — confirming this is a genuinely different, additional mechanism, not a
regression of #2035's fix.

Scope

Both confirmed via direct regex testing in isolation, not just observed in ledger/pipeline output.
Found via a full (uncapped) post-fix name-diff of the whole csharp corpus — 2 non-cascade
GitGalaxy-only occurrences remained out of the shape's current ~47, alongside 44+ genuine
cascade-region local functions (already-validated, unrelated to this issue). Small in absolute
count in this corpus, but confirms the underlying return-type-loop/branch-matching mechanism has
more edge cases than #2035 closed — worth a broader look rather than one-off patches, given how
many distinct symptoms (this.EatToken, GetWellKnownType, ref-as-call-arg, ?-as-ternary) have now
surfaced from what is structurally the same root shape (a bounded-but-imprecise "return type or
modifier" walk that can't always distinguish declaration syntax from call/expression syntax).

Not fixed here

Filing for follow-up rather than fixing immediately — this is the third and fourth distinct
sub-mechanism found in this same regex path this session (#2035 already covered two), and each
new one found so far has needed its own careful, isolated fix + full corpus verification. Worth
a dedicated pass rather than another one-off patch under time pressure.

Found via the tri-comparison-ledger-sweep skill's csharp pass (post-fix re-verification, per the
skill's own "fixing one confirmed bug is not proof the surrounding path is now fully correct"
discipline).

Activity

  1. added
    bug
    on Aug 21, 2026
  2. added 3 commits that reference this issue on Aug 21, 2026
    c02337c
    1237fac
    d2ec1bc
  3. added
    core-engine
    threat: false-positive
    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-positive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions