Skip to content

Fix StackOverflowException in analyzer tests by bypassing Roslyn SDK WeightedMatch Issue#208

Merged
bradwilson merged 2 commits intoxunit:rel/2.0.0from
ana1250:fix_WeightedMatch
Apr 18, 2026
Merged

Fix StackOverflowException in analyzer tests by bypassing Roslyn SDK WeightedMatch Issue#208
bradwilson merged 2 commits intoxunit:rel/2.0.0from
ana1250:fix_WeightedMatch

Conversation

@ana1250
Copy link
Copy Markdown

@ana1250 ana1250 commented Apr 18, 2026

Background

This PR addresses a StackOverflowException observed when running analyzer tests
(X3006 and X3007), particularly on macOS CI, discovered while working on
#207.

The issue appears to be triggered by the diagnostic matching logic in
Microsoft.CodeAnalysis.Testing (see dotnet/roslyn-sdk#1253), where a large number
of similar compiler diagnostics can lead to very deep recursion in the matching
algorithm.

The previous tests used the {{CS0535("ITestCase", 19)}} pattern, which produces
many identical compiler diagnostics for missing interface implementations. These
diagnostics are not relevant to the analyzer behavior being tested, but they
significantly increase matching complexity.


Fix

This change simplifies the tests and avoids generating large numbers of compiler
diagnostics:

  • Removed the CS0535-based diagnostic generation from X3006 and X3007 tests
  • Updated test sources to use direct interface implementations (e.g., : ITestCase)
  • Configured the verifier to use CompilerDiagnostics.None for these cases,
    since compiler errors (CS0535) are expected but not relevant to analyzer behavior
  • Added overloads to VerifyAnalyzerV3NonAot to support configuring compiler diagnostics

This keeps the tests focused on validating analyzer behavior (xUnit3006/xUnit3007)
while avoiding excessive diagnostic matching.


Notes

  • The core analyzer logic is unchanged—this is purely a structural update to the tests.
  • The tests continue to validate analyzer diagnostics and arguments as before.
  • CS0535 compiler errors are expected in these scenarios due to incomplete interface implementations, but they are not relevant to the analyzer behavior being tested. Ignoring them keeps the tests focused and avoids excessive diagnostic matching.

Related

@bradwilson
Copy link
Copy Markdown
Member

Still broken, presumably because I use this technique elsewhere besides your newly introduced tests. I just don't PR my own stuff, so I don't trip this (the CI build only runs on Windows).

I'll pull your branch on my Mac mini and see if I can fix the rest.

@bradwilson bradwilson merged commit e04316f into xunit:rel/2.0.0 Apr 18, 2026
4 checks passed
@bradwilson
Copy link
Copy Markdown
Member

Thanks!

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.

2 participants