@@ -419,17 +419,14 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
419
419
return Address (arg, getFixedBufferAlignment (IGF.IGM ));
420
420
}
421
421
422
- // / Given an abstract type --- a type possibly expressed in terms of
423
- // / unbound generic types --- return the formal type within the type's
424
- // / primary defining context.
425
- static CanType getFormalTypeInContext (CanType abstractType) {
422
+ static CanType getFormalTypeInContext (CanType abstractType, DeclContext *dc) {
426
423
// Map the parent of any non-generic nominal type.
427
424
if (auto nominalType = dyn_cast<NominalType>(abstractType)) {
428
425
// If it doesn't have a parent, or the parent doesn't need remapping,
429
426
// do nothing.
430
427
auto abstractParentType = nominalType.getParent ();
431
428
if (!abstractParentType) return abstractType;
432
- auto parentType = getFormalTypeInContext (abstractParentType);
429
+ auto parentType = getFormalTypeInContext (abstractParentType, dc );
433
430
if (abstractParentType == parentType) return abstractType;
434
431
435
432
// Otherwise, rebuild the type.
@@ -438,14 +435,24 @@ static CanType getFormalTypeInContext(CanType abstractType) {
438
435
439
436
// Map unbound types into their defining context.
440
437
} else if (auto ugt = dyn_cast<UnboundGenericType>(abstractType)) {
441
- return ugt->getDecl ()->getDeclaredTypeInContext ()->getCanonicalType ();
438
+ return dc->mapTypeIntoContext (ugt->getDecl ()->getDeclaredInterfaceType ())
439
+ ->getCanonicalType ();
442
440
443
441
// Everything else stays the same.
444
442
} else {
445
443
return abstractType;
446
444
}
447
445
}
448
446
447
+ // / Given an abstract type --- a type possibly expressed in terms of
448
+ // / unbound generic types --- return the formal type within the type's
449
+ // / primary defining context.
450
+ static CanType getFormalTypeInContext (CanType abstractType) {
451
+ if (auto nominal = abstractType.getAnyNominal ())
452
+ return getFormalTypeInContext (abstractType, nominal);
453
+ return abstractType;
454
+ }
455
+
449
456
// / Get the next argument and use it as the 'self' type metadata.
450
457
static void getArgAsLocalSelfTypeMetadata (IRGenFunction &IGF,
451
458
llvm::Function::arg_iterator &it,
0 commit comments