@@ -4286,15 +4286,25 @@ CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::getNew(
42864286}
42874287
42884288CanTypeWrapper<OpenedArchetypeType> OpenedArchetypeType::get (
4289- Type existential, Optional<UUID> knownID) {
4289+ CanType existential, Optional<UUID> knownID) {
42904290 Type interfaceType = GenericTypeParamType::get (
42914291 /* isTypeSequence=*/ false , 0 , 0 , existential->getASTContext ());
42924292 return get (existential, interfaceType, knownID);
42934293}
42944294
4295- CanOpenedArchetypeType OpenedArchetypeType::get (Type existential,
4295+ CanOpenedArchetypeType OpenedArchetypeType::get (CanType existential,
42964296 Type interfaceType,
42974297 Optional<UUID> knownID) {
4298+ // FIXME: Opened archetypes can't be transformed because the
4299+ // the identity of the archetype has to be preserved. This
4300+ // means that simplifying an opened archetype in the constraint
4301+ // system to replace type variables with fixed types is not
4302+ // yet supported. For now, assert that an opened archetype never
4303+ // contains type variables to catch cases where type variables
4304+ // would be applied to the type-checked AST.
4305+ assert (!existential->hasTypeVariable () &&
4306+ " opened existentials containing type variables cannot be simplified" );
4307+
42984308 auto &ctx = existential->getASTContext ();
42994309 auto &openedExistentialEnvironments =
43004310 ctx.getImpl ().OpenedExistentialEnvironments ;
@@ -4327,17 +4337,18 @@ CanOpenedArchetypeType OpenedArchetypeType::get(Type existential,
43274337}
43284338
43294339
4330- CanType OpenedArchetypeType::getAny (Type existential, Type interfaceType) {
4340+ CanType OpenedArchetypeType::getAny (CanType existential, Type interfaceType) {
43314341 if (auto metatypeTy = existential->getAs <ExistentialMetatypeType>()) {
4332- auto instanceTy = metatypeTy->getExistentialInstanceType ();
4342+ auto instanceTy =
4343+ metatypeTy->getExistentialInstanceType ()->getCanonicalType ();
43334344 return CanMetatypeType::get (
43344345 OpenedArchetypeType::getAny (instanceTy, interfaceType));
43354346 }
43364347 assert (existential->isExistentialType ());
43374348 return OpenedArchetypeType::get (existential, interfaceType);
43384349}
43394350
4340- CanType OpenedArchetypeType::getAny (Type existential) {
4351+ CanType OpenedArchetypeType::getAny (CanType existential) {
43414352 Type interfaceType = GenericTypeParamType::get (
43424353 /* isTypeSequence=*/ false , 0 , 0 , existential->getASTContext ());
43434354 return getAny (existential, interfaceType);
0 commit comments