Fix handling of static virtual method implementation checking (#54710)
authorDavid Wrighton <davidwr@microsoft.com>
Fri, 25 Jun 2021 22:06:22 +0000 (15:06 -0700)
committerGitHub <noreply@github.com>
Fri, 25 Jun 2021 22:06:22 +0000 (15:06 -0700)
commit333c4e72b83a08288db929ac56c0e336c936b655
tree500fbc5de8bde74f508a3f0d4e8a59774f2d57ce
parent24adc911242af6b99a4fc9a6c7f234e6e4df7d53
Fix handling of static virtual method implementation checking (#54710)

- It turns out that GetMethodDescFromMemberDefOrRefOrSpec and FindOrCreateAssociatedMethodDesc are not safe to use on a MemberRef whent  the associated MethodTable is not fully loaded.
- Instead only use that feature when working with a MethodDef or a fully loaded type, and when working with a not fully loaded type, use MemberLoader::FindMethod instead.
- When running the resolution algorithm for doing constraint validation, it also is not necessary to fully resolve to the exact correct MethodDesc, which as that process uses FindOrCreateAssociatedMethodDesc needs to be avoided.
- The above was not evident as in many cases, the validation algorithm did not run as it was misplaced and located directly before the call to SetIsFullyLoaded. That code path is only followed if the type is able to fully load without circular dependencies. (Test case CuriouslyRecurringGenericWithUnimplementedMethod added to cover that scenario)
- In addition, while investigating these issues, I realized we were lacking checks that the constraints on the impl and decl method were not checked at during type load, but that work was instead deferred to dispatch time. Along with the constraint check there was also a set of accessibility checks that had been missed that are common to all MethodImpl handling. Fix by adding tweaking the logic to share most of that code.
src/coreclr/vm/methodtable.cpp
src/coreclr/vm/methodtable.h
src/coreclr/vm/methodtablebuilder.cpp
src/coreclr/vm/methodtablebuilder.h
src/coreclr/vm/runtimehandles.cpp
src/coreclr/vm/typedesc.cpp
src/tests/Loader/classloader/StaticVirtualMethods/NegativeTestCases/CuriouslyRecurringGenericWithUnimplementedMethod.il [new file with mode: 0644]
src/tests/Loader/classloader/StaticVirtualMethods/NegativeTestCases/CuriouslyRecurringGenericWithUnimplementedMethod.ilproj [new file with mode: 0644]
src/tests/Loader/classloader/StaticVirtualMethods/NegativeTestCases/MethodConstraintMismatch.il [new file with mode: 0644]
src/tests/Loader/classloader/StaticVirtualMethods/NegativeTestCases/MethodConstraintMismatch.ilproj [new file with mode: 0644]