Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick the ExplicitInterfaceImplemetation fix #54180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ private static bool CanHaveInheritanceTarget(ISymbol symbol)
return false;
}

if (symbol is INamedTypeSymbol or IEventSymbol or IPropertySymbol ||
symbol.IsOrdinaryMethod())
if (symbol is INamedTypeSymbol or IEventSymbol or IPropertySymbol
or IMethodSymbol { MethodKind: MethodKind.Ordinary or MethodKind.ExplicitInterfaceImplementation })
{
return true;
}
Expand Down
87 changes: 73 additions & 14 deletions src/EditorFeatures/Test/InheritanceMargin/InheritanceMarginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Collections.Immutable;
using System.Linq;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
Expand Down Expand Up @@ -33,6 +32,9 @@ private static Task VerifyInSingleDocumentAsync(
string languageName,
params TestInheritanceMemberItem[] memberItems)
{
markup = @$"<![CDATA[
{markup}]]>";

var workspaceFile = $@"
<Workspace>
<Project Language=""{languageName}"" CommonReferences=""true"">
Expand Down Expand Up @@ -138,12 +140,14 @@ private static async Task VerifyInDifferentProjectsAsync(
<Project Language=""{markup1.languageName}"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<ProjectReference>Assembly2</ProjectReference>
<Document>
{markup1.markupInProject1}
<![CDATA[
{markup1.markupInProject1}]]>
</Document>
</Project>
<Project Language=""{markup2.languageName}"" AssemblyName=""Assembly2"" CommonReferences=""true"">
<Document>
{markup2.markupInProject2}
<![CDATA[
{markup2.markupInProject2}]]>
</Document>
</Project>
</Workspace>";
Expand Down Expand Up @@ -933,18 +937,16 @@ public class {|target5:Bar2|} : Bar1, IBar
[Fact]
public Task TestCSharpFindGenericsBaseType()
{
var lessThanToken = SecurityElement.Escape("<");
var greaterThanToken = SecurityElement.Escape(">");
var markup = $@"
public interface {{|target2:IBar|}}{lessThanToken}T{greaterThanToken}
{{
void {{|target4:Foo|}}();
}}
var markup = @"
public interface {|target2:IBar|}<T>
{
void {|target4:Foo|}();
}

public class {{|target1:Bar2|}} : IBar{lessThanToken}int{greaterThanToken}, IBar{lessThanToken}string{greaterThanToken}
{{
public void {{|target3:Foo|}}();
}}";
public class {|target1:Bar2|} : IBar<int>, IBar<string>
{
public void {|target3:Foo|}();
}";

var itemForIBar = new TestInheritanceMemberItem(
lineNumber: 2,
Expand Down Expand Up @@ -989,6 +991,63 @@ public class {{|target1:Bar2|}} : IBar{lessThanToken}int{greaterThanToken}, IBar
itemForFooInBar2);
}

[Fact]
public Task TestCSharpExplicitInterfaceImplementation()
{
var markup = @"
interface {|target2:IBar|}<T>
{
void {|target3:Foo|}(T t);
}

abstract class {|target1:AbsBar|} : IBar<int>
{
void IBar<int>.{|target4:Foo|}(int t)
{
throw new System.NotImplementedException();
}
}";
var itemForIBar = new TestInheritanceMemberItem(
lineNumber: 2,
memberName: "interface IBar<T>",
targets: ImmutableArray.Create(new TargetInfo(
targetSymbolDisplayName: "class AbsBar",
locationTag: "target1",
relationship: InheritanceRelationship.Implemented)));

var itemForFooInIBar = new TestInheritanceMemberItem(
lineNumber: 4,
memberName: "void IBar<T>.Foo(T)",
targets: ImmutableArray.Create(new TargetInfo(
targetSymbolDisplayName: "void AbsBar.IBar<int>.Foo(int)",
locationTag: "target4",
relationship: InheritanceRelationship.Implemented)));

var itemForAbsBar = new TestInheritanceMemberItem(
lineNumber: 7,
memberName: "class AbsBar",
targets: ImmutableArray.Create(new TargetInfo(
targetSymbolDisplayName: "interface IBar<T>",
locationTag: "target2",
relationship: InheritanceRelationship.Implementing)));

var itemForFooInAbsBar = new TestInheritanceMemberItem(
lineNumber: 9,
memberName: "void AbsBar.IBar<int>.Foo(int)",
targets: ImmutableArray.Create(new TargetInfo(
targetSymbolDisplayName: "void IBar<T>.Foo(T)",
locationTag: "target3",
relationship: InheritanceRelationship.Implementing)));

return VerifyInSingleDocumentAsync(
markup,
LanguageNames.CSharp,
itemForIBar,
itemForFooInIBar,
itemForAbsBar,
itemForFooInAbsBar);
}

#endregion

#region TestsForVisualBasic
Expand Down