Skip to content

Commit 626bea2

Browse files
committed
[ConstraintSystem] Return an existential type in getTypeOfMemberReference
when the member is a typealias to a protocol or composition.
1 parent 6608bf8 commit 626bea2

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
@@ -1767,6 +1767,13 @@ ConstraintSystem::getTypeOfMemberReference(
17671767
auto memberTy = TypeChecker::substMemberTypeWithBase(DC->getParentModule(),
17681768
typeDecl, baseObjTy);
17691769

1770+
// If the member type is a constraint, e.g. because the
1771+
// reference is to a typealias with an underlying protocol
1772+
// or composition type, the member reference has existential
1773+
// type.
1774+
if (memberTy->isConstraintType())
1775+
memberTy = ExistentialType::get(memberTy);
1776+
17701777
checkNestedTypeConstraints(*this, memberTy, locator);
17711778

17721779
// 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)