@@ -4244,19 +4244,25 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
4244
4244
CanType componentTy;
4245
4245
if (!var->getDeclContext ()->isTypeContext ()) {
4246
4246
componentTy = var->getInterfaceType ()->getCanonicalType ();
4247
+ } else if (var->getDeclContext ()->getSelfProtocolDecl () &&
4248
+ baseTy->isExistentialType ()) {
4249
+ componentTy = var->getValueInterfaceType ()->getCanonicalType ();
4250
+ ASSERT (!componentTy->hasTypeParameter ());
4247
4251
} else {
4248
- componentTy =
4252
+ // The mapTypeIntoContext() / mapTypeOutOfContext() dance is there
4253
+ // to handle the case where baseTy being a type parameter subject
4254
+ // to a superclass requirement.
4255
+ componentTy = var->getValueInterfaceType ().subst (
4249
4256
GenericEnvironment::mapTypeIntoContext (genericEnv, baseTy)
4250
- ->getTypeOfMember (var)
4251
- ->getReferenceStorageReferent ()
4257
+ ->getContextSubstitutionMap (var->getDeclContext ()))
4252
4258
->mapTypeOutOfContext ()
4253
4259
->getCanonicalType ();
4260
+ }
4254
4261
4255
- // The component type for an @objc optional requirement needs to be
4256
- // wrapped in an optional.
4257
- if (var->getAttrs ().hasAttribute <OptionalAttr>()) {
4258
- componentTy = OptionalType::get (componentTy)->getCanonicalType ();
4259
- }
4262
+ // The component type for an @objc optional requirement needs to be
4263
+ // wrapped in an optional.
4264
+ if (var->getAttrs ().hasAttribute <OptionalAttr>()) {
4265
+ componentTy = OptionalType::get (componentTy)->getCanonicalType ();
4260
4266
}
4261
4267
4262
4268
if (canStorageUseStoredKeyPathComponent (var, expansion)) {
0 commit comments