@@ -979,8 +979,16 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
979
979
Type t) {
980
980
llvm::DenseMap<SubstitutableType *, TypeVariableType *> types;
981
981
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.
984
992
if (auto archetypeTy = dyn_cast<ArchetypeType>(origType)) {
985
993
return openTypeParameter (cs,
986
994
archetypeTy->getInterfaceType (),
@@ -989,22 +997,20 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
989
997
}
990
998
991
999
// 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
+ });
1008
1014
}
1009
1015
1010
1016
bool TypeChecker::typesSatisfyConstraint (Type type1, Type type2,
0 commit comments