@@ -437,10 +437,14 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
437
437
// Add conditional dependencies for interface methods the type implements. For example, if the type T implements
438
438
// interface IFoo which has a method M1, add a dependency on T.M1 dependent on IFoo.M1 being called, since it's
439
439
// possible for any IFoo object to actually be an instance of T.
440
+ DefType defTypeDefinition = ( DefType ) defType . GetTypeDefinition ( ) ;
440
441
DefType [ ] defTypeRuntimeInterfaces = defType . RuntimeInterfaces ;
442
+ DefType [ ] defTypeDefinitionRuntimeInterfaces = defTypeDefinition . RuntimeInterfaces ;
443
+ Debug . Assert ( defTypeDefinitionRuntimeInterfaces . Length == defTypeRuntimeInterfaces . Length ) ;
441
444
for ( int interfaceIndex = 0 ; interfaceIndex < defTypeRuntimeInterfaces . Length ; interfaceIndex ++ )
442
445
{
443
446
DefType interfaceType = defTypeRuntimeInterfaces [ interfaceIndex ] ;
447
+ DefType interfaceDefinitionType = defTypeDefinitionRuntimeInterfaces [ interfaceIndex ] ;
444
448
445
449
Debug . Assert ( interfaceType . IsInterface ) ;
446
450
@@ -457,11 +461,22 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
457
461
if ( ! isStaticInterfaceMethod && ! needsDependenciesForInstanceInterfaceMethodImpls )
458
462
continue ;
459
463
464
+ MethodDesc interfaceMethodDefinition = interfaceMethod ;
465
+ if ( interfaceType != interfaceDefinitionType )
466
+ interfaceMethodDefinition = factory . TypeSystemContext . GetMethodForInstantiatedType ( interfaceMethodDefinition . GetTypicalMethodDefinition ( ) , ( InstantiatedType ) interfaceDefinitionType ) ;
467
+
460
468
MethodDesc implMethod = isStaticInterfaceMethod ?
461
- defType . ResolveInterfaceMethodToStaticVirtualMethodOnType ( interfaceMethod ) :
462
- defType . ResolveInterfaceMethodToVirtualMethodOnType ( interfaceMethod ) ;
469
+ defTypeDefinition . ResolveInterfaceMethodToStaticVirtualMethodOnType ( interfaceMethodDefinition ) :
470
+ defTypeDefinition . ResolveInterfaceMethodToVirtualMethodOnType ( interfaceMethodDefinition ) ;
463
471
if ( implMethod != null )
464
472
{
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
+
465
480
if ( isStaticInterfaceMethod )
466
481
{
467
482
Debug . Assert ( ! implMethod . IsVirtual ) ;
@@ -500,12 +515,7 @@ public sealed override IEnumerable<CombinedDependencyListEntry> GetConditionalSt
500
515
// Is the implementation provided by a default interface method?
501
516
// If so, add a dependency on the entrypoint directly since nobody else is going to do that
502
517
// (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 ) ;
509
519
if ( resolution == DefaultInterfaceMethodResolution . DefaultImplementation )
510
520
{
511
521
DefType providingInterfaceDefinitionType = ( DefType ) implMethod . OwningType ;
0 commit comments