diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index a2f118adf9fb7..804b2ad93ec26 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
}
// Look for a default implementation last.
- FindAndAddDefaultInterfaceImplementations (type, resolvedInterfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
}
}
}
@@ -279,16 +279,23 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
return context.TryResolve (type)?.BaseType;
}
- // Returns a list of default implementations of the given interface method on this type.
- // Note that this returns a list to potentially cover the diamond case (more than one
- // most specific implementation of the given interface methods). ILLink needs to preserve
- // all the implementations so that the proper exception can be thrown at runtime.
- void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefinition interfaceMethod)
+ ///
+ /// Returns a list of default implementations of the given interface method on this type.
+ /// Note that this returns a list to potentially cover the diamond case (more than one
+ /// most specific implementation of the given interface methods). ILLink needs to preserve
+ /// all the implementations so that the proper exception can be thrown at runtime.
+ ///
+ /// The type that implements (directly or via a base interface) the declaring interface of
+ /// The method to find a default implementation for
+ ///
+ /// The InterfaceImplementation on that points to the DeclaringType of .
+ ///
+ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
- foreach (var interfaceImpl in type.Interfaces) {
+ foreach (var interfaceImpl in typeThatMayHaveDIM.Interfaces) {
var potentialImplInterface = context.TryResolve (interfaceImpl.InterfaceType);
if (potentialImplInterface == null)
continue;
@@ -296,9 +303,9 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
bool foundImpl = false;
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
- if (potentialImplMethod == interfaceMethod &&
+ if (potentialImplMethod == interfaceMethodToBeImplemented &&
!potentialImplMethod.IsAbstract) {
- AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -308,8 +315,8 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
- if (context.TryResolve (@override) == interfaceMethod) {
- AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, @potentialImplMethod));
+ if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -323,7 +330,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
- FindAndAddDefaultInterfaceImplementations (potentialImplInterface, interfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
}
}
}