Intellisense does not suggest Equals, GetHashCode, or ToString as suggestions for override on records
See original GitHub issueVersion 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:
Actual Behavior:
Only Test1
and Test2
are suggested despite being able to override the other three:
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:
- Created 3 years ago
- Reactions:1
- Comments:11 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 debugYou seem to be correct about:
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
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