question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intellisense does not suggest Equals, GetHashCode, or ToString as suggestions for override on records

See original GitHub issue

Version Used:

  • Visual Studio 2019 16.8.0 Preview 3.1
  • Compiler version: ‘3.8.0-4.20472.6 (1e60b393)’. Language version: preview.
  • ,NET SDK 5.0.100-rc.1.20452.10

Steps to Reproduce:

Given the following code with the cursor at the location of $$, invoke Intellisense (IE: Ctrl+Space)

abstract record RecordA // This record is only present so that Intellisense shows *something* for the override suggestions
{
    public abstract void Test1();
    public abstract void Test2();
}

record RecordB : RecordA
{
    override $$
}

Expected Behavior:

Intellisense suggests Equals, GetHashCode, Test1, Test2, and ToString as possible methods to override. Same as if classes were used instead:

image

Actual Behavior:

Only Test1 and Test2 are suggested despite being able to override the other three:

image


This presumably because the compiler already thinks they’re overridden since the synthetic methods are overriding them, but this breaks muscle memory for overriding methods when you want to override them manually.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Youssef1313commented, Sep 22, 2020

https://github.com/dotnet/roslyn/blob/f9fed067fb225a039d70ddfdbc604a96ab3ab253/src/Features/Core/Portable/Completion/Providers/AbstractOverrideCompletionProvider.ItemGetter.cs#L129-L144

Probably GetOverridableMembers isn’t working as expected? Will need to debug


You seem to be correct about:

This presumably because the compiler already thinks they’re overridden since the synthetic methods are overriding them

The following part from GetOverridableMember seem to cause that:

https://github.com/dotnet/roslyn/blob/b61d9d2863eebfc76b032e5f8fcd0a918fb27147/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/INamedTypeSymbolExtensions.cs#L529-L530

I’ll debug soon to confirm

0reactions
PathogenDavidcommented, Oct 17, 2020

you probably don’t want Equals(object? obj) in there

Oops, I missed the fact you can’t override Equals(object) on records when I originally filed this issue, I probably shouldn’t have mentioned it.

Also that’s covered by https://github.com/dotnet/roslyn/issues/48640

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hiding GetHashCode/Equals/ToString from fluent interface ...
I tried overriding these methods in a couple of the classes, attaching the EditorBrowsableAttribute attribute to each, but they still show up.
Read more >
code assist intellisense does not work
oWord.selection. Equals GetHashCode GetType ToString. does not give assist except for the above and gives these same selections always for everything.
Read more >
Generate C# Equals and GetHashCode Method Overrides
Override the GetHashCode method to allow a type to work correctly in a hash table. Read more guidance on equality operators.
Read more >
Generate Overrides for equals(), hashCode() and toString()
Generate Overrides for equals(), hashCode() and toString(). We can generate the code to override the equals and hashCode methods.
Read more >
How to Override Equals and GetHashCode Methods in ...
Introduction. Equals method is intended to return true when another object is supplied which is semantically equal to current instance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found