@@ -956,9 +956,12 @@ namespace {
956956 // If we had a return type of 'Self', erase it.
957957 Type resultTy;
958958 resultTy = cs.getType (result);
959- if (resultTy->hasOpenedExistentialWithRoot (record.Archetype )) {
960- Type erasedTy = constraints::typeEraseOpenedArchetypesWithRoot (
961- resultTy, record.Archetype );
959+
960+ auto *env = record.Archetype ->getGenericEnvironment ();
961+
962+ if (resultTy->hasLocalArchetypeFromEnvironment (env)) {
963+ Type erasedTy = constraints::typeEraseOpenedArchetypesFromEnvironment (
964+ resultTy, env);
962965 auto range = result->getSourceRange ();
963966 result = coerceToType (result, erasedTy, locator);
964967 // FIXME: Implement missing tuple-to-tuple conversion
@@ -1668,8 +1671,8 @@ namespace {
16681671 } else {
16691672 // Erase opened existentials from the type of the thunk; we're
16701673 // going to open the existential inside the thunk's body.
1671- containerTy = constraints::typeEraseOpenedArchetypesWithRoot (
1672- containerTy, knownOpened->second );
1674+ containerTy = constraints::typeEraseOpenedArchetypesFromEnvironment (
1675+ containerTy, knownOpened->second -> getGenericEnvironment () );
16731676 selfTy = containerTy;
16741677 }
16751678 }
@@ -1732,8 +1735,8 @@ namespace {
17321735 // If the base was an opened existential, erase the opened
17331736 // existential.
17341737 if (openedExistential) {
1735- refType = constraints::typeEraseOpenedArchetypesWithRoot (
1736- refType, baseTy->castTo <OpenedArchetypeType>());
1738+ refType = constraints::typeEraseOpenedArchetypesFromEnvironment (
1739+ refType, baseTy->castTo <OpenedArchetypeType>()-> getGenericEnvironment () );
17371740 }
17381741
17391742 return refType;
@@ -1958,8 +1961,8 @@ namespace {
19581961 getConstraintSystem ().getConstraintLocator (memberLocator));
19591962 if (knownOpened != solution.OpenedExistentialTypes .end ()) {
19601963 curryThunkTy =
1961- constraints::typeEraseOpenedArchetypesWithRoot (
1962- curryThunkTy, knownOpened->second )
1964+ constraints::typeEraseOpenedArchetypesFromEnvironment (
1965+ curryThunkTy, knownOpened->second -> getGenericEnvironment () )
19631966 ->castTo <FunctionType>();
19641967 }
19651968 }
0 commit comments