Skip to content

Commit

Permalink
Don't give duplicate member error for explicit implementations of dif…
Browse files Browse the repository at this point in the history
…ferent file-local interfaces with same source name
  • Loading branch information
RikkiGibson committed May 27, 2023
1 parent 32b9156 commit c8889b1
Show file tree
Hide file tree
Showing 2 changed files with 492 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1948,10 +1948,23 @@ private void CheckMemberNameConflicts(BindingDiagnosticBag diagnostics)
{
if (symbol.Kind != SymbolKind.Field || !symbol.IsImplicitlyDeclared)
{
// The type '{0}' already contains a definition for '{1}'
if (Locations.Length == 1 || IsPartial)
var explicitImplementations = symbol.GetExplicitInterfaceImplementations();
var lastExplicitImplementations = lastSym.GetExplicitInterfaceImplementations();

// Source symbols can only explicitly implement at most 1 member
Debug.Assert(explicitImplementations.Length is 0 or 1 && explicitImplementations.Length == lastExplicitImplementations.Length);

// Sometimes two non-overloadable members can have exactly the same source name, but be explicit implementations of different members.
// For example, when explicitly implementing members of file-local interfaces.
// We don't consider such members to be duplicates.
if (explicitImplementations.Length == 0
|| explicitImplementations[0].Equals(lastExplicitImplementations[0], TypeCompareKind.AllIgnoreOptions))
{
diagnostics.Add(ErrorCode.ERR_DuplicateNameInClass, symbol.GetFirstLocation(), this, symbol.Name);
// The type '{0}' already contains a definition for '{1}'
if (Locations.Length == 1 || IsPartial)
{
diagnostics.Add(ErrorCode.ERR_DuplicateNameInClass, symbol.GetFirstLocation(), this, symbol.Name);
}
}
}

Expand Down
Loading

0 comments on commit c8889b1

Please sign in to comment.