From ac02b66e41041e1cefd355eacaddb45bcb4f1741 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 19 Aug 2023 23:06:43 +0000 Subject: [PATCH] Use symbol comparison in `CustomMarshallerAttributeAnalyzer` (#90850) * Use symbol comparison in `CustomMarshallerAttributeAnalyzer` * Pass SymbolEqualityComparer --- .../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 fb97a71d5e47c..493e206e3c423 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, SymbolEqualityComparer.Default)) { INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!; IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0);