Skip to content

Fix csharp func_start: bare comma and ternary-? absorbed as return-type tokens - #2057

Merged
squid-protocol merged 1 commit into
mainfrom
fix/csharp-ref-ternary-false-positives-2054
Aug 21, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/csharp-ref-ternary-false-positives-2054

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #2054. The two specific cases from that issue (ref mdName, inside a call-argument list, a ternary ? inside a switch-expression arm) both traced to the same root cause: the func_start return-type-loop's per-token character class allowed a bare comma with no bracket/paren requirement, so a run of comma-separated call arguments could be absorbed as if they were return-type tokens, landing on the call's own target identifier as a phantom function.

Fix

Moved comma-tolerance into explicit <...>/[...] single-token alternatives (generics, arrays — tuple commas already had \([^()]{0,80}\)) instead of allowing a bare comma anywhere. Added (?!\?) at each token's start to reject a token beginning with ?, closing the ternary-operator case (string?'s ? ends a token, never starts one, so real nullable types are unaffected).

An important note on process

My first attempt at this fix was dispatched to a Gemini/agy subagent, which implemented essentially the same regex change but hit a sandbox permission wall partway through verification and couldn't complete the corpus-level check. I re-verified independently and initially misread a large drop in one file's function count (LanguageParser.cs: 673→474 raw DB count) as a severe regression and almost discarded the fix. On closer inspection — diffing the exact function names lost, not just the count — every single one of the ~190 total "lost" occurrences across 4 files (LanguageParser.cs, CSharpCompilation.cs, MethodCompiler.cs, Workspace.cs) is a receiver.method-shaped phantom name (this.EatToken, _syntaxFactory.TypeConstraint, modifiers.ToList, solution.Workspace.GetDocumentName, etc.) with zero real declaration anywhere in its file — confirmed by direct source inspection, not assumption. The fix generalizes much further than the 2 originally-scoped cases, which is a good thing, not a regression; I was wrong to be alarmed by the raw count alone. Re-implemented and re-verified the same fix myself from scratch after discarding the subagent's uncommitted attempt, per this repo's own standing rule about not trusting a raw number without reading the actual disputed source.

Also found and fixed two unrelated environment gaps in this worktree's .crucible_venvs/full_precision (missing pytest, then missing networkx/tiktoken/pandas/numpy/xgboost/pyyaml entirely) — the crucible check was silently falling back to zero-dependency-mode results while reporting "full_precision: PASS", masking real verification. Fixed both before trusting any PASS result from that venv.

Verification

  • Both target repro cases confirmed fixed (no match); ref-return, nullable-return, generic-with-comma, and tuple-return still all match correctly; the two csharp func_start: return-type loop swallows call-expression fragments as fake return types #2035 cases (GetWellKnownType, this.EatToken) still don't reproduce.
  • pytest tests/extraction/languages/test_csharp.py tests/extraction/languages/test_csharp_strict.py: 167 passed.
  • ReDoS pathological-input timing probe (long token, many tuples, many bare commas): all sub-10ms.
  • ruff_audit.py --ci / mypy_audit.py --ci: no new findings.
  • crucible_check.py --mode both, run with genuine full-precision dependencies present (not the silently-degraded state): PASS/PASS after re-blessing both golden masters. Diff confined to csharp, zero unrelated-language ripple.
  • Direct per-file name-diff (not just count) on all 4 affected files confirms zero real functions lost, zero new false positives gained.
  • Full, uncapped re-check of the csharp/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter] ledger shape: now 44/44 occurrences confirmed genuine (cascade-region local functions), 0 non-cascade false positives remaining.

Test plan

  • Both target false positives fixed, confirmed via isolated regex testing.
  • Zero real-function regressions across every affected file, confirmed by per-name diff, not just count.
  • Full crucible corpus check PASS/PASS with genuine full-precision dependencies, both golden masters re-blessed.
  • The ledger shape this fix targets is now fully clean (0 non-cascade occurrences remaining).

…pe tokens

The return-type-loop's per-token character class allowed a bare comma
outside any bracket/paren, letting the walk absorb comma-separated CALL
ARGUMENTS (`ref mdName,`/`SpecialType.None,` inside a multi-line call) as
if they were return-type tokens, landing on the call's own target
identifier as a phantom function name. A real C# return type never has a
bare top-level comma outside a tuple's own parens, a generic's own angle
brackets, or an array's own brackets -- moved comma-tolerance into explicit
`<...>`/`[...]` single-token alternatives instead of allowing it bare.

Also added `(?!\?)` at each token's start to reject a token beginning with
`?`, closing a ternary operator (`\n ? expr`) being consumed as if it were
a nullable-type marker (`string?`, where `?` never starts a token, only
ends the preceding one).

Confirmed via a full corpus diff this retroactively closes ~190
previously-unknown phantom occurrences sharing the identical root cause
(this.EatToken, this.ParseXxx, _syntaxFactory.Xxx, modifiers.ToList, etc.
across LanguageParser.cs, CSharpCompilation.cs, MethodCompiler.cs, and
Workspace.cs) -- every one confirmed to have zero real declaration
anywhere in its file, only call sites, by direct source inspection. Zero
real functions lost, zero new false positives introduced (a pure-narrowing
character-class change).

The csharp/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter]
ledger shape is now fully clean: 44/44 remaining occurrences confirmed
genuine (local functions inside LanguageParser.cs's known tree-sitter
parse-error cascade region), zero non-cascade false positives.

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

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit c02337c into main Aug 21, 2026
26 of 27 checks passed
@squid-protocol
squid-protocol deleted the fix/csharp-ref-ternary-false-positives-2054 branch August 21, 2026 21:22
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant