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

Do not show unspeakable names in override completion #47979

Merged
5 commits merged into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -4,6 +4,7 @@

using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
Expand Down Expand Up @@ -3044,6 +3045,7 @@ public override bool Bar(Baz baz)
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(47941, "https://github.com/dotnet/roslyn/issues/47941")]
public async Task OverrideInRecordWithoutExplicitOverriddenMember()
{
await VerifyItemExistsAsync(@"record Program
Expand All @@ -3053,6 +3055,7 @@ await VerifyItemExistsAsync(@"record Program
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(47941, "https://github.com/dotnet/roslyn/issues/47941")]
public async Task OverrideInRecordWithExplicitOverriddenMember()
{
await VerifyItemIsAbsentAsync(@"record Program
Expand All @@ -3062,5 +3065,25 @@ await VerifyItemIsAbsentAsync(@"record Program
override $$
}", "ToString()");
}

[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(47973, "https://github.com/dotnet/roslyn/issues/47973")]
public async Task NoCloneInOverriddenRecord()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also need a VB test for VB code inheriting the C# Record?

{
// Currently WellKnownMemberNames.CloneMethodName is not public, so we can't reference it directly. We
// could hardcode in the value "<Clone>$", however if the compiler ever changed the name and we somehow
// started showing it in completion, this test would continue to pass. So this allows us to at least go
// back and explicitly validate this scenario even in that event.
var cloneMemberName = (string)typeof(WellKnownMemberNames).GetField("CloneMethodName", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
Assert.Equal("<Clone>$", cloneMemberName);
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

await VerifyItemIsAbsentAsync(@"
record Base();

record Program : Base
{
override $$
}", cloneMemberName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -551,30 +551,25 @@ private static void AddOverridableMembers(

private static bool IsOverridable(ISymbol member, INamedTypeSymbol containingType)
{
if (member.IsAbstract || member.IsVirtual || member.IsOverride)
{
if (member.IsSealed)
{
return false;
}
if (!member.IsAbstract && !member.IsVirtual && !member.IsOverride)
return false;

if (!member.IsAccessibleWithin(containingType))
{
return false;
}
if (member.IsSealed)
return false;

switch (member.Kind)
{
case SymbolKind.Event:
return true;
case SymbolKind.Method:
return ((IMethodSymbol)member).MethodKind == MethodKind.Ordinary;
case SymbolKind.Property:
return !((IPropertySymbol)member).IsWithEvents;
}
}
if (!member.CanBeReferencedByName)
return false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the new check. the rest is just making teh method consistent with flow control.


return false;
if (!member.IsAccessibleWithin(containingType))
return false;

return member switch
{
IEventSymbol => true,
IMethodSymbol { MethodKind: MethodKind.Ordinary } => true,
IPropertySymbol { IsWithEvents: false } => true,
_ => false,
};
}

private static void RemoveOverriddenMembers(
Expand Down