Skip to content

Commit 4efa9ea

Browse files
committed
Sema: Update getTypeOfMemberReference() for subclass existentials
If the member came from a class, we're not going to substitute the 'Self' type. Instead, we open the existential, upcast the archetype up to the class type and access the member as if it were a class member in the usual way.
1 parent b1d22ff commit 4efa9ea

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,12 @@ ConstraintSystem::getTypeOfMemberReference(
12141214
type = openedFnType->replaceSelfParameterType(baseObjTy);
12151215
}
12161216

1217-
// When accessing members of an existential, replace the 'Self' type
1218-
// parameter with the existential type, since formally the access will
1219-
// operate on existentials and not type parameters.
1220-
if (!isDynamicResult && baseObjTy->isExistentialType()) {
1217+
// When accessing protocol members with an existential base, replace
1218+
// the 'Self' type parameter with the existential type, since formally
1219+
// the access will operate on existentials and not type parameters.
1220+
if (!isDynamicResult &&
1221+
baseObjTy->isExistentialType() &&
1222+
outerDC->getAsProtocolOrProtocolExtensionContext()) {
12211223
auto selfTy = replacements[
12221224
cast<GenericTypeParamType>(outerDC->getSelfInterfaceType()
12231225
->getCanonicalType())];
@@ -1226,7 +1228,7 @@ ConstraintSystem::getTypeOfMemberReference(
12261228
t = selfTy->getSelfType();
12271229
if (t->is<TypeVariableType>())
12281230
if (t->isEqual(selfTy))
1229-
return baseObjTy;
1231+
return baseObjTy;
12301232
if (auto *metatypeTy = t->getAs<MetatypeType>())
12311233
if (metatypeTy->getInstanceType()->isEqual(selfTy))
12321234
return ExistentialMetatypeType::get(baseObjTy);

0 commit comments

Comments
 (0)