-
Notifications
You must be signed in to change notification settings - Fork 19
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
Inherited classes Equals ignored when called from the base class #38
Comments
This is definitely a bug, thanks for raising it. |
I think we still want to keep the EqualityComparer for value types as to avoid unnecessary boxing. So use Object.Equals only for reference types. I might have some time this week to look at this, unless you'd like to have a go at it yourself and send a PR! Let me know! |
Yes, that sounds right! I just started playing with generators yesterday (they are great, I should have used them earlier), and I'm swamped right now so I wouldn't be able to make a PR in the next two weeks. However if the issue is still open early next year, I'll definitely try my hand at it :) Thanks for responding! |
I looked into this issue this morning, I think the fix is a bit more involved. Basically, all the comparers use EqualityComparer.Default for the element comparison -- these need also be fixed, my view is that we create another comparer, let's say In this comparison, at the static ctor, we check whether the type is a reference type && not sealed, if so, then on Equals/Hashcode operations we call the Object methods, else, we call the EqualityComparer methods. @ssttgg does it sound good to you? |
@christianrondeau this should be fixed now in 2.7.2. |
Wow that's great, before the end of the holidays even! Hope you are having a great time, and thanks! |
First of all, great library, thanks for making it!
Problem
When calling
.Equals()
orSystem.Collections.Generic.EqualityComparer
on a base class that uses[Equatable]
, the generatedEquals
implementation will not call inheritedEquals
implementations.[Equatable]
, reference equality is used (which is not what we want)[Equatable]
, the base class only checks it's own fields and ignores inherited types fields.Reproduction
Solution
This code is generated in the container:
This shorts-circuits the concrete type by directly checking the base type. This would work:
Version
.NET 6.0, Generator.Equals 2.6.0
Thanks!
The text was updated successfully, but these errors were encountered: