Skip to content

Commit

Permalink
Compare symbols instead of fully qualified name (dotnet#72507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jul 20, 2022
1 parent aa91495 commit c046354
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,30 @@ public override void Initialize(AnalysisContext context)
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterCompilationStartAction(
compilationContext =>
context =>
{
// Nothing to do if the LibraryImportAttribute is not in the compilation
INamedTypeSymbol? libraryImportAttrType = compilationContext.Compilation.GetTypeByMetadataName(TypeNames.LibraryImportAttribute);
INamedTypeSymbol? libraryImportAttrType = context.Compilation.GetTypeByMetadataName(TypeNames.LibraryImportAttribute);
if (libraryImportAttrType == null)
return;
INamedTypeSymbol? marshalAsAttrType = compilationContext.Compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute);
INamedTypeSymbol? marshalAsAttrType = context.Compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute);
var knownUnsupportedTypes = new List<ITypeSymbol>(s_unsupportedTypeNames.Length);
foreach (string typeName in s_unsupportedTypeNames)
{
INamedTypeSymbol? unsupportedType = compilationContext.Compilation.GetTypeByMetadataName(typeName);
INamedTypeSymbol? unsupportedType = context.Compilation.GetTypeByMetadataName(typeName);
if (unsupportedType != null)
{
knownUnsupportedTypes.Add(unsupportedType);
}
}
compilationContext.RegisterSymbolAction(symbolContext => AnalyzeSymbol(symbolContext, knownUnsupportedTypes, marshalAsAttrType), SymbolKind.Method);
context.RegisterSymbolAction(symbolContext => AnalyzeSymbol(symbolContext, knownUnsupportedTypes, marshalAsAttrType, libraryImportAttrType), SymbolKind.Method);
});
}

private static void AnalyzeSymbol(SymbolAnalysisContext context, List<ITypeSymbol> knownUnsupportedTypes, INamedTypeSymbol? marshalAsAttrType)
private static void AnalyzeSymbol(SymbolAnalysisContext context, List<ITypeSymbol> knownUnsupportedTypes, INamedTypeSymbol? marshalAsAttrType, INamedTypeSymbol libraryImportAttrType)
{
var method = (IMethodSymbol)context.Symbol;

Expand All @@ -82,7 +82,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, List<ITypeSymbo
// This can be the case when the generator creates an extern partial function for blittable signatures.
foreach (AttributeData attr in method.GetAttributes())
{
if (attr.AttributeClass?.ToDisplayString() == TypeNames.LibraryImportAttribute)
if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, libraryImportAttrType))
{
return;
}
Expand Down

0 comments on commit c046354

Please sign in to comment.