Skip to content

Add CS0649 suppressor for MEF imported fields#737

Merged
AArnott merged 2 commits into
mainfrom
aarnott-suppress-cs0649
Jun 19, 2026
Merged

Add CS0649 suppressor for MEF imported fields#737
AArnott merged 2 commits into
mainfrom
aarnott-suppress-cs0649

Conversation

@AArnott

@AArnott AArnott commented Jun 19, 2026

Copy link
Copy Markdown
Member

Why

MEF assigns imported fields during composition, so valid imported fields can trigger CS0649 even though they are populated at runtime. This change adds the missing suppressor and documents it alongside the existing analyzer catalog.

What changed

  • add VSMEF018 to suppress CS0649 on imported fields of exported MEF parts
  • keep the compiler-diagnostic suppressors C#-only by moving CS0649 and CS8618 suppressors into the C# analyzer assembly
  • add focused compiler-level tests for the new suppressor and a VB test showing there is no equivalent VB compiler warning in the same scenario
  • register the new suppressor in the multi-analyzer test harness
  • document the new suppressor in docfx/analyzers/ and the analyzer package README
  • record the analyzer doc update locations in .github/copilot-instructions.md so future analyzer additions update the docs consistently

Notes for reviewers

The VB probe changed the shape of the implementation a bit: instead of keeping a C#-only suppressor in the shared analyzer assembly with an RS1004 suppression, the compiler-specific suppressors now live in the C# analyzer assembly. A small shared helper in that assembly keeps the import/export detection logic consistent between CS0649 and CS8618.

Add a C#-only suppressor for CS0649 on MEF-imported fields, move compiler-specific suppressors into the CSharp analyzer assembly, add compiler-level tests for C# and VB behavior, and document the new suppressor in the analyzer docs and repo instructions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 19, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the VS MEF analyzer package with a new compiler diagnostic suppressor to reduce false-positive warnings for MEF-imported fields that are assigned at composition time, and updates the related test and documentation infrastructure.

Changes:

  • Add VSMEF018 to suppress CS0649 for MEF imported fields on exported parts.
  • Move compiler-diagnostic suppressors to the C# analyzer assembly and share import/export detection logic via a new helper utility.
  • Add targeted tests (including a VB “no equivalent warning” probe) and update README/DocFX documentation + Copilot instructions.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Microsoft.VisualStudio.Composition.Analyzers.Tests/Helpers/CSharpMultiAnalyzerVerifier+Test.cs Registers the new suppressor in the multi-analyzer harness.
test/Microsoft.VisualStudio.Composition.Analyzers.Tests/CS0649ImportingMemberSuppressorTests.cs Adds compiler-level tests validating CS0649 suppression behavior and a VB probe test.
src/Microsoft.VisualStudio.Composition.Analyzers/README.md Documents VSMEF018 in the suppressor catalog table.
src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/ImportingMemberSuppressorUtilities.cs Introduces shared utilities for consistent MEF import/export detection in suppressors.
src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/CS8618ImportingMemberSuppressor.cs Moves/adjusts CS8618 suppressor to be C#-only and to use the shared utilities.
src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/CS0649ImportingMemberSuppressor.cs Adds the new CS0649 suppressor implementation.
docfx/analyzers/VSMEF018.md Adds a DocFX page describing the new suppressor.
docfx/analyzers/toc.yml Adds VSMEF018 to the analyzer docs TOC.
docfx/analyzers/index.md Adds VSMEF018 to the analyzer docs index.
.github/copilot-instructions.md Records analyzer/suppressor documentation update locations for future contributions.

Narrow the suppressor to IFieldSymbol since CS0649 only applies to fields, keeping the implementation strongly typed and clearer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AArnott AArnott enabled auto-merge (squash) June 19, 2026 15:38
@AArnott AArnott merged commit c8426fe into main Jun 19, 2026
9 checks passed
@AArnott AArnott deleted the aarnott-suppress-cs0649 branch June 19, 2026 15:51
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.

3 participants