@@ -3419,23 +3419,32 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3419
3419
ArrayRef<ProtocolConformanceRef> indexHashables,
3420
3420
CanType baseTy,
3421
3421
bool forPropertyDescriptor) {
3422
+ auto baseDecl = storage;
3423
+
3424
+ // ABI-compatible overrides do not have property descriptors, so we need
3425
+ // to reference the overridden declaration instead.
3426
+ if (isa<ClassDecl>(baseDecl->getDeclContext ())) {
3427
+ while (!baseDecl->isValidKeyPathComponent ())
3428
+ baseDecl = baseDecl->getOverriddenDecl ();
3429
+ }
3430
+
3422
3431
// / Returns true if a key path component for the given property or
3423
3432
// / subscript should be externally referenced.
3424
3433
auto shouldUseExternalKeyPathComponent = [&]() -> bool {
3425
3434
return (!forPropertyDescriptor &&
3426
- (storage ->getModuleContext () != SwiftModule ||
3427
- storage ->isResilient (SwiftModule, expansion)) &&
3435
+ (baseDecl ->getModuleContext () != SwiftModule ||
3436
+ baseDecl ->isResilient (SwiftModule, expansion)) &&
3428
3437
// Protocol requirements don't have nor need property descriptors.
3429
- !isa<ProtocolDecl>(storage ->getDeclContext ()) &&
3438
+ !isa<ProtocolDecl>(baseDecl ->getDeclContext ()) &&
3430
3439
// Properties that only dispatch via ObjC lookup do not have nor
3431
3440
// need property descriptors, since the selector identifies the
3432
3441
// storage.
3433
3442
// Properties that are not public don't need property descriptors
3434
3443
// either.
3435
- (!storage ->hasAnyAccessors () ||
3436
- (!getAccessorDeclRef (getRepresentativeAccessorForKeyPath (storage ))
3444
+ (!baseDecl ->hasAnyAccessors () ||
3445
+ (!getAccessorDeclRef (getRepresentativeAccessorForKeyPath (baseDecl ))
3437
3446
.isForeign &&
3438
- getAccessorDeclRef (getRepresentativeAccessorForKeyPath (storage ))
3447
+ getAccessorDeclRef (getRepresentativeAccessorForKeyPath (baseDecl ))
3439
3448
.getLinkage (ForDefinition) <= SILLinkage::PublicNonABI)));
3440
3449
};
3441
3450
@@ -3465,10 +3474,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3465
3474
3466
3475
// ABI-compatible overrides do not have property descriptors, so we need
3467
3476
// to reference the overridden declaration instead.
3468
- auto *baseDecl = externalDecl;
3469
- if (isa<ClassDecl>(baseDecl->getDeclContext ())) {
3470
- while (!baseDecl->isValidKeyPathComponent ())
3471
- baseDecl = baseDecl->getOverriddenDecl ();
3477
+ if (baseDecl != externalDecl) {
3472
3478
externalSubs = SubstitutionMap::getOverrideSubstitutions (baseDecl,
3473
3479
externalDecl,
3474
3480
externalSubs);
0 commit comments