Extract diagnostic reporting out of COM class generator#125308
Merged
jkoritzinsky merged 8 commits intodotnet:mainfrom Mar 10, 2026
Merged
Extract diagnostic reporting out of COM class generator#125308jkoritzinsky merged 8 commits intodotnet:mainfrom
jkoritzinsky merged 8 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors COM class generation by moving diagnostic reporting responsibilities out of ComClassGenerator and into a dedicated Roslyn analyzer, keeping the generator focused on code emission.
Changes:
- Introduced
ComClassGeneratorDiagnosticsAnalyzerto report COM class diagnostics via analyzer infrastructure. - Updated COM class diagnostics tests to validate analyzer-reported diagnostics rather than generator-reported diagnostics.
- Simplified generator plumbing by removing shared “diagnostic splitting/reporting” helper extensions and adjusting
ComClassInfoto return nullable results instead ofDiagnosticOr<T>.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorOutputShape.cs | Small assertion refactor for type argument validation. |
| src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorDiagnostics.cs | Switches verification to run the new diagnostics analyzer and expands diagnostic test cases. |
| src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalGeneratorInitializationContextExtensions.cs | Removes diagnostics registration helpers no longer used after diagnostics extraction. |
| src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticOr.cs | Removes DiagnosticOr<T> incremental-provider helper extensions now unused. |
| src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassInfo.cs | Converts from DiagnosticOr<ComClassInfo> to ComClassInfo? and defers diagnostics to the analyzer. |
| src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs | Updates generator pipeline to use TryGetFrom and filter null results. |
| src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComClassGeneratorDiagnosticsAnalyzer.cs | New analyzer that reports COM class diagnostics and suppresses warnings when errors are present. |
Comments suppressed due to low confidence (1)
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs:40
- After filtering with
.Where(info => info is not null),infois still a nullable reference type (ComClassInfo?) for subsequent stages. WithNullable=enableandTreatWarningsAsErrors=truein this repo, passinginfotoItemAndSyntaxes<ComClassInfo>and dereferencing it will produce nullability warnings that fail the build. Consider unwrapping to a non-nullable provider (e.g., add a.Select(info => info!)after theWhere, or use a helper that returnsIncrementalValuesProvider<ComClassInfo>).
.Where(static info => info is not null);
var classInfoType = attributedClasses
.Select(static (info, ct) => new ItemAndSyntaxes<ComClassInfo>(info,
[
GenerateClassInfoType(info.ImplementedInterfacesNames.Array).NormalizeWhitespace(),
GenerateClassInfoAttributeOnUserType(info.ContainingSyntaxContext, info.ClassSyntax).NormalizeWhitespace()
]));
....InteropServices/gen/ComInterfaceGenerator/Analyzers/ComClassGeneratorDiagnosticsAnalyzer.cs
Outdated
Show resolved
Hide resolved
....InteropServices/gen/ComInterfaceGenerator/Analyzers/ComClassGeneratorDiagnosticsAnalyzer.cs
Show resolved
Hide resolved
jtschuster
reviewed
Mar 9, 2026
Member
jtschuster
left a comment
There was a problem hiding this comment.
Just a couple nits from me
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassInfo.cs
Outdated
Show resolved
Hide resolved
....InteropServices/gen/ComInterfaceGenerator/Analyzers/ComClassGeneratorDiagnosticsAnalyzer.cs
Show resolved
Hide resolved
jkoritzinsky
approved these changes
Mar 9, 2026
This was referenced Mar 10, 2026
Open
…arguments to begin with
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.
No description provided.