@@ -437,10 +437,14 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
437437 // Add conditional dependencies for interface methods the type implements. For example, if the type T implements
438438 // interface IFoo which has a method M1, add a dependency on T.M1 dependent on IFoo.M1 being called, since it's
439439 // possible for any IFoo object to actually be an instance of T.
440+ DefType defTypeDefinition = ( DefType ) defType . GetTypeDefinition ( ) ;
440441 DefType [ ] defTypeRuntimeInterfaces = defType . RuntimeInterfaces ;
442+ DefType [ ] defTypeDefinitionRuntimeInterfaces = defTypeDefinition . RuntimeInterfaces ;
443+ Debug . Assert ( defTypeDefinitionRuntimeInterfaces . Length == defTypeRuntimeInterfaces . Length ) ;
441444 for ( int interfaceIndex = 0 ; interfaceIndex < defTypeRuntimeInterfaces . Length ; interfaceIndex ++ )
442445 {
443446 DefType interfaceType = defTypeRuntimeInterfaces [ interfaceIndex ] ;
447+ DefType interfaceDefinitionType = defTypeDefinitionRuntimeInterfaces [ interfaceIndex ] ;
444448
445449 Debug . Assert ( interfaceType . IsInterface ) ;
446450
@@ -457,11 +461,22 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
457461 if ( ! isStaticInterfaceMethod && ! needsDependenciesForInstanceInterfaceMethodImpls )
458462 continue ;
459463
464+ MethodDesc interfaceMethodDefinition = interfaceMethod ;
465+ if ( interfaceType != interfaceDefinitionType )
466+ interfaceMethodDefinition = factory . TypeSystemContext . GetMethodForInstantiatedType ( interfaceMethodDefinition . GetTypicalMethodDefinition ( ) , ( InstantiatedType ) interfaceDefinitionType ) ;
467+
460468 MethodDesc implMethod = isStaticInterfaceMethod ?
461- defType . ResolveInterfaceMethodToStaticVirtualMethodOnType ( interfaceMethod ) :
462- defType . ResolveInterfaceMethodToVirtualMethodOnType ( interfaceMethod ) ;
469+ defTypeDefinition . ResolveInterfaceMethodToStaticVirtualMethodOnType ( interfaceMethodDefinition ) :
470+ defTypeDefinition . ResolveInterfaceMethodToVirtualMethodOnType ( interfaceMethodDefinition ) ;
463471 if ( implMethod != null )
464472 {
473+ TypeDesc implType = defType ;
474+ while ( ! implType . HasSameTypeDefinition ( implMethod . OwningType ) )
475+ implType = implType . BaseType ;
476+
477+ if ( ! implType . IsTypeDefinition )
478+ implMethod = factory . TypeSystemContext . GetMethodForInstantiatedType ( implMethod . GetTypicalMethodDefinition ( ) , ( InstantiatedType ) implType ) ;
479+
465480 if ( isStaticInterfaceMethod )
466481 {
467482 Debug . Assert ( ! implMethod . IsVirtual ) ;
@@ -500,12 +515,7 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
500515 // Is the implementation provided by a default interface method?
501516 // If so, add a dependency on the entrypoint directly since nobody else is going to do that
502517 // (interface types have an empty vtable, modulo their generic dictionary).
503- TypeDesc interfaceOnDefinition = defType . GetTypeDefinition ( ) . RuntimeInterfaces [ interfaceIndex ] ;
504- MethodDesc interfaceMethodDefinition = interfaceMethod ;
505- if ( ! interfaceType . IsTypeDefinition )
506- interfaceMethodDefinition = factory . TypeSystemContext . GetMethodForInstantiatedType ( interfaceMethod . GetTypicalMethodDefinition ( ) , ( InstantiatedType ) interfaceOnDefinition ) ;
507-
508- var resolution = defType . GetTypeDefinition ( ) . ResolveInterfaceMethodToDefaultImplementationOnType ( interfaceMethodDefinition , out implMethod ) ;
518+ var resolution = defTypeDefinition . ResolveInterfaceMethodToDefaultImplementationOnType ( interfaceMethodDefinition , out implMethod ) ;
509519 if ( resolution == DefaultInterfaceMethodResolution . DefaultImplementation )
510520 {
511521 DefType providingInterfaceDefinitionType = ( DefType ) implMethod . OwningType ;
0 commit comments