-
Notifications
You must be signed in to change notification settings - Fork 369
Update analyzers for C# 14.0 language version checks #1159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
|
I'm hoping to be able to get to this later today 🙂 |
Fixes some analyzers not triggering correctly with Roslyn 5.0 when using C# 14.0.
PR Checklist