Repository navigation
Default the C# 15 test project to the preview language version - #4192
Merged
Merged
Conversation
Roslyn has no LanguageVersion.CSharp15 value while C# 15 is in preview, so LightupHelpers.SupportsCSharp15 was false in the C# 15 test project and the preview default in the test verifiers never applied: tests that did not pass a language version ran as C# 14. Detect the C# 15 compiler by its union syntax kind instead (test-only helper TestLanguageVersion), share the default between the diagnostic and code fix verifiers, and drop the explicit LanguageVersion.Preview arguments that the union tests passed only to work around this.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4192 +/- ##
=======================================
Coverage 97.53% 97.53%
=======================================
Files 1249 1250 +1
Lines 133404 133401 -3
Branches 4290 4290
=======================================
+ Hits 130110 130111 +1
+ Misses 2153 2149 -4
Partials 1141 1141 🚀 New features to boost your workflow:
|
AArnott
marked this pull request as ready for review
October 9, 2026 13:53
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The C# 15 test project was supposed to run every test with
LanguageVersion.Preview, but a plainnew CSharpTest()there actually ran as C# 14.Why
StyleCopDiagnosticVerifierandStyleCopCodeFixVerifierchose the preview default only whenLightupHelpers.SupportsCSharp15was true. That checks for aLanguageVersion.CSharp15enum value, and Roslyn doesn't define one while C# 15 is in preview, including the 5.10 preview the C# 15 tests use. So the check was always false, and tests fell back to the compiler's default, C# 14. The union tests from #4188 and #4191 worked around this by passingLanguageVersion.Previewexplicitly.Change
TestLanguageVersioninStyleCop.Analyzers.Test/Helpers:SupportsCSharp15is true whenLightupHelpers.SupportsCSharp15is true, or when the compiler'sSyntaxKindhasUnionDeclaration. Only the C# 15 test project references a compiler with unions, and the check keeps working once Roslyn addsCSharp15.DefaultreturnsLanguageVersionEx.Previewin that case andnullotherwise, so every other test project behaves exactly as before.TestLanguageVersion.Default, which replaces the two duplicateGetDefaultLanguageVersion()methods.LanguageVersion.Previewarguments from the C# 15 union tests (16 files) along with theusing Microsoft.CodeAnalysis.CSharp;lines they no longer need, and updated their header comments.UnionDeclarationSyntaxWrapperCSharp15UnitTestskeeps its explicitCSharpParseOptions(LanguageVersion.Preview), because it parses outside the verifiers.Effect on existing tests
No existing C# 15 test changed behavior. Locally (net6.0, Linux), the C# 15 project's failing set on this branch matches
masterexactly: 9,563 tests, with the same 303 failing cases (199 test names), all of them the known Linux line-ending code-fix differences that pass on Windows CI. To check that the new default really applies, I temporarily made it returnnull. 18 of the 32 union tests then failed.So none of the inherited C# 6–14 tests depend on C# 14 vs. preview semantics today. I found no analyzer bugs.