You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[mono] UnsafeAccessor to a virtual method on a base class through a derived type asserts #89212
Actually this fails on NativeAOT as well (at runtime!):
System.MissingMethodException: Method not found: 'BaseVirtual'.
at Internal.Runtime.TypeLoaderExceptionHelper.CreateMissingMethodException(ExceptionStringID, String) + 0x63
at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowMissingMethodException(ExceptionStringID, String) + 0x25
at UnsafeAccessorsTests.<Verify_InheritanceMethodResolution_BaseViaDerived>g__BaseVirtual|33_0(UnsafeAccessorsTests.InheritanceDerived target) + 0x1f
at UnsafeAccessorsTests.Verify_InheritanceMethodResolution_BaseViaDerived() + 0x4b
CoreCLR works and the same code without UnsafeAccessor:
If so, I don't see why one would declare this as InheritanceDerived, when the target method is defined on a different type. It isn't as if I can know about non-public methods by looking at a derived type. The first thing I would do would be to look at InheritanceDerived, not see a non-public method and be rather confused.
Personally I agree with Michal's comment in the other issue that this "should" work. That said I'd be fine if we said that we don't want this to work. But then all runtimes should behave consistently.
Especially differences between CoreCLR and NativeAOT are dangerous (since we promise that AOTed apps behave the same as non-AOTed app)
I think the work in Mono is just to replace the assert that the target class is equal to the method's class by a check that the target class is assignable to the method's class.
Activity
vitek-karas commentedon Jul 19, 2023
Actually this fails on NativeAOT as well (at runtime!):
CoreCLR works and the same code without
UnsafeAccessor:will also work (probably on all runtimes, although I didn't try that).
@AaronRobinsonMSFT @MichalStrehovsky what do you think - should this work?
MichalStrehovsky commentedon Jul 19, 2023
Well method
BaseVirtualis not onInheritanceDerivedso this is not expected to work.This is what I brough up in #86932 (comment) and was rejected.
AaronRobinsonMSFT commentedon Jul 19, 2023
@vitek-karas If I update as following it works, right?
If so, I don't see why one would declare this as
InheritanceDerived, when the target method is defined on a different type. It isn't as if I can know about non-public methods by looking at a derived type. The first thing I would do would be to look atInheritanceDerived, not see a non-public method and be rather confused.MichalStrehovsky commentedon Jul 19, 2023
Does this work with CoreCLR?
vitek-karas commentedon Jul 19, 2023
Yes - it does work on CoreCLR.
MichalStrehovsky commentedon Jul 19, 2023
@AaronRobinsonMSFT I think this should be in 8.0. We need to either block this in CoreCLR, or fix in NativeAOT/Mono.
MichalStrehovsky commentedon Jul 19, 2023
Btw, I think the CoreCLR behavior is the correct one
vitek-karas commentedon Jul 19, 2023
Personally I agree with Michal's comment in the other issue that this "should" work. That said I'd be fine if we said that we don't want this to work. But then all runtimes should behave consistently.
Especially differences between CoreCLR and NativeAOT are dangerous (since we promise that AOTed apps behave the same as non-AOTed app)
AaronRobinsonMSFT commentedon Jul 19, 2023
What needs to happen then in NativeAOT? Based on some offline conversations with @fanyang-mono, I believe she is looking into enabling it on mono.
MichalStrehovsky commentedon Jul 19, 2023
We'd walk into the base type, like we do when resolving a MemberRef:
runtime/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs
Line 525 in 9343b2f
(I assume it matches what CoreCLR does in the
UnsafeAccessorcase too.)AaronRobinsonMSFT commentedon Jul 19, 2023
Yep. I just used the
MethodIterator. Seems like it does that under the covers but it wasn't obvious.lambdageek commentedon Jul 20, 2023
I think the work in Mono is just to replace the assert that the target class is equal to the method's class by a check that the target class is assignable to the method's class.
fanyang-mono commentedon Jul 25, 2023
This has been resolved via #89217.