-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix reflection to work with default interface methods #16034
Fix reflection to work with default interface methods #16034
Conversation
|
@atsushikan Could you have a look please? Cc @sergiy-k |
src/mscorlib/src/System/RtType.cs
Outdated
| RuntimeMethodHandleInternal classRtMethodHandle = GetTypeHandleInternal().GetInterfaceMethodImplementation(ifaceRtTypeHandle, ifaceRtMethodHandle); | ||
|
|
||
| if (slot == -1) continue; | ||
| if (classRtMethodHandle.IsNullHandle()) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is preexisting but the "continue" should be on its own line.
|
Other than that, LGTM |
| (RuntimeMethodHandle.GetAttributes(methodHandle) & MethodAttributes.RTSpecialName) == 0 || | ||
| RuntimeMethodHandle.GetName(methodHandle).Equals(".cctor")); | ||
|
|
||
| if ((methodAttributes & MethodAttributes.RTSpecialName) != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this check up to align with how this is done for the else (not interface) case below.
|
@atsushikan I had to also add what I had to do to fix reflection invoke because I didn't realize this hits that code path with the assert (I worked on several things in parallel in my local branch and Invoke didn't have tests ready yet...) |
| RuntimeMethodHandle.GetName(methodHandle).Equals(".ctor") || | ||
| RuntimeMethodHandle.GetName(methodHandle).Equals(".cctor") || | ||
| RuntimeMethodHandle.GetName(methodHandle).StartsWith("IL_STUB", StringComparison.Ordinal)); | ||
| (RuntimeMethodHandle.GetAttributes(methodHandle) & MethodAttributes.RTSpecialName) == 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could now use the cached value for methodAttributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but I would also have to update the "not an interface" case below to do the same to stay consistent. I'm not convinced it's worth the noise in git blame.
|
LGTM. Is there anything that needs to happen on the Invoke path on Project N? |
I'll open that particular can of worms later. Btw: do you know of any other parts of the CLR reflection stack that would need updating? |
|
Reflection doesn't even expose method .overrides today so these things are going to be largely invisible to the apis that walk up base class chains to generate lists of methods. (Assuming interface defaults work the same way as other .overrides- i.e. you have to invoke them through the interface-typed So I imagine any update, if any, will come in the form of requests to add or change the behavior of apis - not so much bug fixes. Or at least documentation that anticipates user confusion (why does |
Fixes #15645.
Fixes #15644.