Skip to content

Commit 8fe5396

Browse files
committed
[ConstraintSystem] Return an existential type in getTypeOfMemberReference
when the member is a typealias to a protocol or composition.
1 parent 449c7eb commit 8fe5396

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,13 @@ ConstraintSystem::getTypeOfMemberReference(
17361736
auto memberTy = TypeChecker::substMemberTypeWithBase(DC->getParentModule(),
17371737
typeDecl, baseObjTy);
17381738

1739+
// If the member type is a constraint, e.g. because the
1740+
// reference is to a typealias with an underlying protocol
1741+
// or composition type, the member reference has existential
1742+
// type.
1743+
if (memberTy->isConstraintType())
1744+
memberTy = ExistentialType::get(memberTy);
1745+
17391746
checkNestedTypeConstraints(*this, memberTy, locator);
17401747

17411748
// Convert any placeholders and open any generics.

test/type/explicit_existential.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,12 @@ extension MyError {
193193
return true
194194
}
195195
}
196+
197+
struct Wrapper {
198+
typealias E = Error
199+
}
200+
201+
func typealiasMemberReferences(metatype: Wrapper.Type) {
202+
let _: Wrapper.E.Protocol = metatype.E.self
203+
let _: (any Wrapper.E).Type = metatype.E.self
204+
}

0 commit comments

Comments
 (0)