Merge pull request #74375 from raulsntos/dotnet/ignore-explicit-interface-implementations

C#: Ignore explicit interface implementations
This commit is contained in:
Rémi Verschelde 2023-03-05 13:39:45 +01:00
commit 5dccc940e7
No known key found for this signature in database
GPG key ID: C3336907360768E1
4 changed files with 34 additions and 2 deletions

View file

@ -194,6 +194,32 @@ namespace Godot.SourceGenerators
location?.SourceTree?.FilePath));
}
public static void ReportExportedMemberIsExplicitInterfaceImplementation(
GeneratorExecutionContext context,
ISymbol exportedMemberSymbol
)
{
var locations = exportedMemberSymbol.Locations;
var location = locations.FirstOrDefault(l => l.SourceTree != null) ?? locations.FirstOrDefault();
string message = $"Attempted to export explicit interface property implementation: " +
$"'{exportedMemberSymbol.ToDisplayString()}'";
string description = $"{message}. Explicit interface implementations can't be exported." +
" Remove the '[Export]' attribute.";
context.ReportDiagnostic(Diagnostic.Create(
new DiagnosticDescriptor(id: "GD0106",
title: message,
messageFormat: message,
category: "Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description),
location,
location?.SourceTree?.FilePath));
}
public static void ReportSignalDelegateMissingSuffix(
GeneratorExecutionContext context,
INamedTypeSymbol delegateSymbol)

View file

@ -113,7 +113,7 @@ namespace Godot.SourceGenerators
var propertySymbols = members
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
.Cast<IPropertySymbol>()
.Where(s => !s.IsIndexer);
.Where(s => !s.IsIndexer && s.ExplicitInterfaceImplementations.Length == 0);
var fieldSymbols = members
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)

View file

@ -151,6 +151,12 @@ namespace Godot.SourceGenerators
continue;
}
if (property.ExplicitInterfaceImplementations.Length > 0)
{
Common.ReportExportedMemberIsExplicitInterfaceImplementation(context, property);
continue;
}
var propertyType = property.Type;
var marshalType = MarshalUtils.ConvertManagedTypeToMarshalType(propertyType, typeCache);

View file

@ -113,7 +113,7 @@ namespace Godot.SourceGenerators
var propertySymbols = members
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Property)
.Cast<IPropertySymbol>()
.Where(s => !s.IsIndexer);
.Where(s => !s.IsIndexer && s.ExplicitInterfaceImplementations.Length == 0);
var fieldSymbols = members
.Where(s => !s.IsStatic && s.Kind == SymbolKind.Field && !s.IsImplicitlyDeclared)