-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix Attribute implementations of Equals and GetHashCode #6240
Conversation
@atsushikan Do we want to take this change, to reduce differences between CoreCLR and CoreRT? |
Yep, this looks a good thing to fix. |
@jkotas @atsushikan Will any of the same reflection access restrictions apply as with CoreRT? |
@dotnet-bot test this please |
@leppie Could you please exclude the test from this PR, and add it as xunit test to corefx instead? We prefer to have tests for framework APIs like this one in corefx. Thank you! The change looks good to me otherwise. |
@jkotas Will do, but probably only during the weekend |
…eal with derived types. #6232
@jkotas Rebased and removed the test. Will get on the test next. |
@jkotas Now that the fix is in, can I build a test for it yet on |
Correct. It may fit well into existing http://github.com/dotnet/corefx/blob/master/src/System.Runtime/tests/System/AttributeTests.cs |
This ports dotnet/coreclr#6240 over to Project N. The TL;DR version of the change is "private fields in base classes are no longer disregarded by Equals()/GetHashCode()". In fact, changing ExposeToDerivedClasses() to return true always is sufficient to effect the desired change. The rest of the delta is just the result of constant-folding and dead-coding from that point. [tfs-changeset: 1657635]
Properly deals with derived types.
Fix #6232
Please advise where to provide tests.
Note: This fix actually seems to match the same behavior as CoreRT.
Notes:
Type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
will NOT return any non-visible fields from base classes.NonPublic
only applies to declared fields in the type it is called on.FlattenHierarchy
does not help here as it applies only tostatic
members, but it's description is actually appropriate here. I suggest a documentation update.This came as a surprise to me too, even after 15 years of .NET.
PS: This might be the oldest bug in existence. It is present in .NET 2.0 and the rotor sources. Unfortunately I cannot verify it again anything earlier than .NET 2.