@@ -979,8 +979,16 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
979979 Type t) {
980980 llvm::DenseMap<SubstitutableType *, TypeVariableType *> types;
981981
982- return t.subst (
983- [&](SubstitutableType *origType) -> Type {
982+ // FIXME: This operation doesn't really make sense with a generic function type.
983+ // We should open the signature instead.
984+ if (auto *gft = t->getAs <GenericFunctionType>()) {
985+ t = FunctionType::get (gft->getParams (), gft->getResult (), gft->getExtInfo ());
986+ }
987+
988+ return t.transformRec (
989+ [&](TypeBase *origType) -> std::optional<Type> {
990+ // FIXME: By folding primary and opaque archetypes together, this doesn't
991+ // really capture the correct semantics for opaque archetypes.
984992 if (auto archetypeTy = dyn_cast<ArchetypeType>(origType)) {
985993 return openTypeParameter (cs,
986994 archetypeTy->getInterfaceType (),
@@ -989,22 +997,20 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
989997 }
990998
991999 // FIXME: Remove this case
992- auto *paramTy = cast<GenericTypeParamType>(origType);
993- auto found = types.find (paramTy);
994- if (found != types.end ())
995- return found->second ;
996-
997- auto locator = cs.getConstraintLocator ({});
998- auto replacement = cs.createTypeVariable (locator,
999- TVO_CanBindToNoEscape);
1000- types[paramTy] = replacement;
1001- return replacement;
1002- },
1003- MakeAbstractConformanceForGenericType (),
1004- // FIXME: By folding primary and opaque archetypes together, this doesn't
1005- // really capture the correct semantics for opaque archetypes.
1006- SubstFlags::SubstitutePrimaryArchetypes |
1007- SubstFlags::SubstituteOpaqueArchetypes);
1000+ if (auto *paramTy = dyn_cast<GenericTypeParamType>(origType)) {
1001+ auto found = types.find (paramTy);
1002+ if (found != types.end ())
1003+ return found->second ;
1004+
1005+ auto locator = cs.getConstraintLocator ({});
1006+ auto replacement = cs.createTypeVariable (locator,
1007+ TVO_CanBindToNoEscape);
1008+ types[paramTy] = replacement;
1009+ return replacement;
1010+ }
1011+
1012+ return std::nullopt ;
1013+ });
10081014}
10091015
10101016bool TypeChecker::typesSatisfyConstraint (Type type1, Type type2,
0 commit comments