Skip to content

Conversation

@Sergio0694
Copy link
Member

Fixes some analyzers not triggering correctly with Roslyn 5.0 when using C# 14.0.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tested code with current supported SDKs
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

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.
@Sergio0694 Sergio0694 added mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit analyzer 👓 A new analyzer being implemented or updated labels Jan 28, 2026
@Sergio0694 Sergio0694 requested a review from Copilot January 28, 2026 00:23
Copy link

Copilot AI left a 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.CSharp imports where needed for LanguageVersion.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.

@MichaelShapiro
Copy link

Hi. Thanks for working on this issue. Is there an ETA for a release that includes this PR?

@Sergio0694
Copy link
Member Author

I'm hoping to be able to get to this later today 🙂

@Sergio0694 Sergio0694 merged commit 67c676c into main Feb 2, 2026
15 checks passed
@Sergio0694 Sergio0694 deleted the dev/mvvm-analyzers-fixes branch February 2, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analyzer 👓 A new analyzer being implemented or updated mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants