Update analyzers for C# 14.0 language version checks#1159
Merged
Sergio0694 merged 2 commits intomainfrom Feb 2, 2026
Merged
Conversation
Replaced preview language version checks with explicit C# 14.0 or greater checks using HasLanguageVersionAtLeastEqualTo when available. This ensures analyzers correctly handle new language versioning and maintain compatibility with Roslyn 5.0.0 or greater.
Introduces new unit tests under the ROSLYN_5_0_0_OR_GREATER conditional to verify analyzer diagnostics and code generation behavior when using C# 14. These tests ensure correct warnings are produced for observable properties and WinRT compatibility in this language version.
There was a problem hiding this comment.
Pull request overview
Updates analyzer language-version gating so analyzers that depend on partial-properties behavior trigger correctly when using Roslyn 5.0 with LangVersion=14.0 (not just Preview), and adds coverage for the C# 14 case.
Changes:
- Add C# 14.0-specific unit tests (guarded by
ROSLYN_5_0_0_OR_GREATER) to ensure expected diagnostics are produced. - Update analyzers to treat C# 14.0+ as satisfying the “partial properties available” requirement when building against Roslyn 5.0.
- Add conditional
Microsoft.CodeAnalysis.CSharpimports where needed forLanguageVersion.CSharp14.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/CommunityToolkit.Mvvm.SourceGenerators.Roslyn4120.UnitTests/Test_SourceGeneratorsDiagnostics.cs | Adds LanguageVersion.CSharp14 test cases under Roslyn 5.0 to validate analyzer behavior. |
| src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/WinRTObservablePropertyOnFieldsIsNotAotCompatibleAnalyzer.cs | Switches the “stop early” language-version check to C# 14+ for Roslyn 5.0, preserving Preview behavior for older Roslyn. |
| src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/UseObservablePropertyOnSemiAutoPropertyAnalyzer.cs | Updates the analyzer’s language-version gate to allow C# 14+ under Roslyn 5.0 (instead of requiring Preview). |
| src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/UseObservablePropertyOnPartialPropertyAnalyzer.cs | Updates the analyzer’s language-version gate to allow C# 14+ under Roslyn 5.0 (instead of requiring Preview). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...vvm.SourceGenerators/Diagnostics/Analyzers/UseObservablePropertyOnPartialPropertyAnalyzer.cs
Show resolved
Hide resolved
...vm.SourceGenerators/Diagnostics/Analyzers/UseObservablePropertyOnSemiAutoPropertyAnalyzer.cs
Show resolved
Hide resolved
...enerators/Diagnostics/Analyzers/WinRTObservablePropertyOnFieldsIsNotAotCompatibleAnalyzer.cs
Show resolved
Hide resolved
|
Hi. Thanks for working on this issue. Is there an ETA for a release that includes this PR? |
Member
Author
|
I'm hoping to be able to get to this later today 🙂 |
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.
Fixes some analyzers not triggering correctly with Roslyn 5.0 when using C# 14.0.
PR Checklist