Skip to content

Commit 859110c

Browse files
committed
Stop opening the "bound" generic signature of an opaque type declaration.
Creation of the "bound" generic signature isn't possible with interface types or type variables, so open up the opaque interface signature instead and separately bind the outer type parameters as appropriate.
1 parent d14bd85 commit 859110c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements) {
837837

838838
Type ConstraintSystem::openOpaqueType(OpaqueTypeArchetypeType *opaque,
839839
ConstraintLocatorBuilder locator) {
840-
auto opaqueLocatorKey = getOpenOpaqueLocator(locator, opaque->getDecl());
840+
auto opaqueDecl = opaque->getDecl();
841+
auto opaqueLocatorKey = getOpenOpaqueLocator(locator, opaqueDecl);
841842

842843
// If we have already opened this opaque type, look in the known set of
843844
// replacements.
@@ -858,9 +859,22 @@ Type ConstraintSystem::openOpaqueType(OpaqueTypeArchetypeType *opaque,
858859
// corresponding to the underlying type should be the constraints on the
859860
// underlying return type.
860861
auto opaqueLocator = locator.withPathElement(
861-
LocatorPathElt::OpenedOpaqueArchetype(opaque->getDecl()));
862+
LocatorPathElt::OpenedOpaqueArchetype(opaqueDecl));
862863
OpenedTypeMap replacements;
863-
openGeneric(DC, opaque->getBoundSignature(), opaqueLocator, replacements);
864+
openGeneric(DC, opaqueDecl->getOpaqueInterfaceGenericSignature(),
865+
opaqueLocator, replacements);
866+
867+
// If there is an outer generic signature, bind the outer parameters based
868+
// on the substitutions in the opaque type.
869+
auto subs = opaque->getSubstitutions();
870+
if (auto genericSig = subs.getGenericSignature()) {
871+
for (auto *genericParamPtr : genericSig.getGenericParams()) {
872+
Type genericParam(genericParamPtr);
873+
addConstraint(
874+
ConstraintKind::Bind, openType(genericParam, replacements),
875+
genericParam.subst(subs), opaqueLocator);
876+
}
877+
}
864878

865879
recordOpenedTypes(opaqueLocatorKey, replacements);
866880

0 commit comments

Comments
 (0)