Skip to content

Default the C# 15 test project to the preview language version - #4192

Merged
AArnott merged 1 commit into
masterfrom
csharp15-default-preview
Oct 9, 2026
Merged

AArnott merged 1 commit into
masterfrom
csharp15-default-preview

Conversation

@AArnott

@AArnott AArnott commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The C# 15 test project was supposed to run every test with LanguageVersion.Preview, but a plain new CSharpTest() there actually ran as C# 14.

Why

StyleCopDiagnosticVerifier and StyleCopCodeFixVerifier chose the preview default only when LightupHelpers.SupportsCSharp15 was true. That checks for a LanguageVersion.CSharp15 enum 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 passing LanguageVersion.Preview explicitly.

Change

  • New test-only helper TestLanguageVersion in StyleCop.Analyzers.Test/Helpers:
    • SupportsCSharp15 is true when LightupHelpers.SupportsCSharp15 is true, or when the compiler's SyntaxKind has UnionDeclaration. Only the C# 15 test project references a compiler with unions, and the check keeps working once Roslyn adds CSharp15.
    • Default returns LanguageVersionEx.Preview in that case and null otherwise, so every other test project behaves exactly as before.
  • Both verifiers use TestLanguageVersion.Default, which replaces the two duplicate GetDefaultLanguageVersion() methods.
  • Removed the explicit LanguageVersion.Preview arguments from the C# 15 union tests (16 files) along with the using Microsoft.CodeAnalysis.CSharp; lines they no longer need, and updated their header comments. UnionDeclarationSyntaxWrapperCSharp15UnitTests keeps its explicit CSharpParseOptions(LanguageVersion.Preview), because it parses outside the verifiers.
  • No product code changes.

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 master exactly: 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 return null. 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.

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.
@AArnott AArnott changed the title csharp15 default preview Default the C# 15 test project to the preview language version Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.53%. Comparing base (e43d042) to head (376a6ec).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott added this pull request to stack #4194 October 9, 2026 13:53
@AArnott
AArnott marked this pull request as ready for review October 9, 2026 13:53
@AArnott
AArnott merged commit a19eede into master Oct 9, 2026
25 checks passed
@AArnott
AArnott deleted the csharp15-default-preview branch October 9, 2026 13:56
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.

1 participant