From 0cc56745ae249726593f969c0f7076ba36e940da Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 19 Aug 2023 23:04:37 +0300 Subject: [PATCH 1/2] Use symbol comparison in `CustomMarshallerAttributeAnalyzer` --- .../Analyzers/CustomMarshallerAttributeAnalyzer.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs index fb97a71d5e47cc..fe108519bf9bd8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs @@ -618,9 +618,9 @@ public override void Initialize(AnalysisContext context) private void PrepareForAnalysis(CompilationStartAnalysisContext context) { - if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is not null) + if (context.Compilation.GetBestTypeByMetadataName(TypeNames.CustomMarshallerAttribute) is { } customMarshallerAttribute) { - var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation); + var perCompilationAnalyzer = new PerCompilationAnalyzer(context.Compilation, customMarshallerAttribute); context.RegisterOperationAction(perCompilationAnalyzer.AnalyzeAttribute, OperationKind.Attribute); } } @@ -630,10 +630,12 @@ private sealed partial class PerCompilationAnalyzer private readonly Compilation _compilation; private readonly INamedTypeSymbol _spanOfT; private readonly INamedTypeSymbol _readOnlySpanOfT; + private readonly INamedTypeSymbol _customMarshallerAttribute; - public PerCompilationAnalyzer(Compilation compilation) + public PerCompilationAnalyzer(Compilation compilation, INamedTypeSymbol customMarshallerAttribute) { _compilation = compilation; + _customMarshallerAttribute = customMarshallerAttribute; _spanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_Span_Metadata); _readOnlySpanOfT = compilation.GetBestTypeByMetadataName(TypeNames.System_ReadOnlySpan_Metadata); } @@ -641,7 +643,7 @@ public void AnalyzeAttribute(OperationAnalysisContext context) { IAttributeOperation attr = (IAttributeOperation)context.Operation; if (attr.Operation is IObjectCreationOperation attrCreation - && attrCreation.Type.ToDisplayString() == TypeNames.CustomMarshallerAttribute) + && attrCreation.Type.Equals(_customMarshallerAttribute)) { INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!; IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0); From 098f667c7af79e80131dd4a7cbd564612c8b1c72 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sun, 20 Aug 2023 00:00:18 +0300 Subject: [PATCH 2/2] Pass SymbolEqualityComparer --- .../Analyzers/CustomMarshallerAttributeAnalyzer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs index fe108519bf9bd8..493e206e3c423e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs @@ -643,7 +643,7 @@ public void AnalyzeAttribute(OperationAnalysisContext context) { IAttributeOperation attr = (IAttributeOperation)context.Operation; if (attr.Operation is IObjectCreationOperation attrCreation - && attrCreation.Type.Equals(_customMarshallerAttribute)) + && attrCreation.Type.Equals(_customMarshallerAttribute, SymbolEqualityComparer.Default)) { INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!; IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0);