Skip to content

Commit 17707f6

Browse files
committed
Short-circuit recursive ResolveInterfaceMethodToVirtualMethodOnType
When ResolveInterfaceMethodToVirtualMethodOnType is recursively calling itself, use the result instead of returning `null` and then continuing the outer loop that is effectively doing the same recursion on base types.
1 parent 924c611 commit 17707f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public override MethodDesc ResolveVariantInterfaceMethodToStaticVirtualMethodOnT
610610
// function returns null if the interface method implementation is not defined by the current type in
611611
// the hierarchy.For variance to work correctly, this requires that interfaces be queried in correct order.
612612
// See current interface call resolution for details on how that happens.
613-
private static MethodDesc ResolveInterfaceMethodToVirtualMethodOnType(MethodDesc interfaceMethod, MetadataType currentType)
613+
private static MethodDesc ResolveInterfaceMethodToVirtualMethodOnType(MethodDesc interfaceMethod, MetadataType currentType, bool returnRecursive = false)
614614
{
615615
Debug.Assert(!interfaceMethod.Signature.IsStatic);
616616

@@ -665,7 +665,7 @@ private static MethodDesc ResolveInterfaceMethodToVirtualMethodOnType(MethodDesc
665665
MethodDesc baseClassImplementationOfInterfaceMethod = ResolveInterfaceMethodToVirtualMethodOnTypeRecursive(interfaceMethod, baseType);
666666
if (baseClassImplementationOfInterfaceMethod != null)
667667
{
668-
return null;
668+
return returnRecursive ? baseClassImplementationOfInterfaceMethod : null;
669669
}
670670
else
671671
{
@@ -716,6 +716,7 @@ public static MethodDesc ResolveVariantInterfaceMethodToVirtualMethodOnType(Meth
716716
// Helper routine used during implicit interface implementation discovery
717717
private static MethodDesc ResolveInterfaceMethodToVirtualMethodOnTypeRecursive(MethodDesc interfaceMethod, MetadataType currentType)
718718
{
719+
MethodDesc savedResult = null;
719720
while (true)
720721
{
721722
if (currentType == null)
@@ -729,7 +730,7 @@ private static MethodDesc ResolveInterfaceMethodToVirtualMethodOnTypeRecursive(M
729730
return null;
730731
}
731732

732-
MethodDesc currentTypeInterfaceResolution = ResolveInterfaceMethodToVirtualMethodOnType(interfaceMethod, currentType);
733+
MethodDesc currentTypeInterfaceResolution = ResolveInterfaceMethodToVirtualMethodOnType(interfaceMethod, currentType, returnRecursive: true);
733734
if (currentTypeInterfaceResolution != null)
734735
return currentTypeInterfaceResolution;
735736

0 commit comments

Comments
 (0)