Skip to content

Commit

Permalink
Merge pull request #74375 from raulsntos/dotnet/ignore-explicit-inter…
Browse files Browse the repository at this point in the history
…face-implementations

C#: Ignore explicit interface implementations
  • Loading branch information
akien-mga committed Mar 5, 2023
2 parents 9ab52d8 + 0372bd5 commit 5dccc94
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
26 changes: 26 additions & 0 deletions modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ ISymbol exportedMemberSymbol
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ INamedTypeSymbol symbol
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ INamedTypeSymbol symbol
continue;
}

if (property.ExplicitInterfaceImplementations.Length > 0)
{
Common.ReportExportedMemberIsExplicitInterfaceImplementation(context, property);
continue;
}

var propertyType = property.Type;
var marshalType = MarshalUtils.ConvertManagedTypeToMarshalType(propertyType, typeCache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ INamedTypeSymbol symbol
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)
Expand Down

0 comments on commit 5dccc94

Please sign in to comment.