Skip to content

Commit ff7157b

Browse files
authored
Deduplicate diagnostics emitted for managed->unmanaged and unmanaged->managed stubs (#88803)
1 parent 138cb59 commit ff7157b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,25 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
9999
.Combine(interfaceContexts.Collect())
100100
.SelectMany((data, ct) => GroupComContextsForInterfaceGeneration(data.Left, data.Right, ct));
101101

102-
// Generate the code for the managed-to-unmanaged stubs and the diagnostics from code-generation.
103-
context.RegisterDiagnostics(interfaceAndMethodsContexts
104-
.SelectMany((data, ct) => data.DeclaredMethods.SelectMany(m => m.ManagedToUnmanagedStub.Diagnostics)));
102+
// Generate the code for the managed-to-unmanaged stubs.
105103
var managedToNativeInterfaceImplementations = interfaceAndMethodsContexts
106104
.Select(GenerateImplementationInterface)
107105
.WithTrackingName(StepNames.GenerateManagedToNativeInterfaceImplementation)
108106
.WithComparer(SyntaxEquivalentComparer.Instance)
109107
.SelectNormalized();
110108

111-
// Generate the code for the unmanaged-to-managed stubs and the diagnostics from code-generation.
112-
context.RegisterDiagnostics(interfaceAndMethodsContexts
113-
.SelectMany((data, ct) => data.DeclaredMethods.SelectMany(m => m.UnmanagedToManagedStub.Diagnostics)));
109+
// Generate the code for the unmanaged-to-managed stubs.
114110
var nativeToManagedVtableMethods = interfaceAndMethodsContexts
115111
.Select(GenerateImplementationVTableMethods)
116112
.WithTrackingName(StepNames.GenerateNativeToManagedVTableMethods)
117113
.WithComparer(SyntaxEquivalentComparer.Instance)
118114
.SelectNormalized();
119115

116+
// Report diagnostics for managed-to-unmanaged and unmanaged-to-managed stubs, deduplicating diagnostics that are reported for both.
117+
context.RegisterDiagnostics(
118+
interfaceAndMethodsContexts
119+
.SelectMany((data, ct) => data.DeclaredMethods.SelectMany(m => m.ManagedToUnmanagedStub.Diagnostics).Union(data.DeclaredMethods.SelectMany(m => m.UnmanagedToManagedStub.Diagnostics))));
120+
120121
// Generate the native interface metadata for each [GeneratedComInterface]-attributed interface.
121122
var nativeInterfaceInformation = interfaceContexts
122123
.Select(static (data, ct) => data.Info)

0 commit comments

Comments
 (0)