@@ -956,9 +956,12 @@ namespace {
956
956
// If we had a return type of 'Self', erase it.
957
957
Type resultTy;
958
958
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);
962
965
auto range = result->getSourceRange ();
963
966
result = coerceToType (result, erasedTy, locator);
964
967
// FIXME: Implement missing tuple-to-tuple conversion
@@ -1668,8 +1671,8 @@ namespace {
1668
1671
} else {
1669
1672
// Erase opened existentials from the type of the thunk; we're
1670
1673
// 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 () );
1673
1676
selfTy = containerTy;
1674
1677
}
1675
1678
}
@@ -1732,8 +1735,8 @@ namespace {
1732
1735
// If the base was an opened existential, erase the opened
1733
1736
// existential.
1734
1737
if (openedExistential) {
1735
- refType = constraints::typeEraseOpenedArchetypesWithRoot (
1736
- refType, baseTy->castTo <OpenedArchetypeType>());
1738
+ refType = constraints::typeEraseOpenedArchetypesFromEnvironment (
1739
+ refType, baseTy->castTo <OpenedArchetypeType>()-> getGenericEnvironment () );
1737
1740
}
1738
1741
1739
1742
return refType;
@@ -1958,8 +1961,8 @@ namespace {
1958
1961
getConstraintSystem ().getConstraintLocator (memberLocator));
1959
1962
if (knownOpened != solution.OpenedExistentialTypes .end ()) {
1960
1963
curryThunkTy =
1961
- constraints::typeEraseOpenedArchetypesWithRoot (
1962
- curryThunkTy, knownOpened->second )
1964
+ constraints::typeEraseOpenedArchetypesFromEnvironment (
1965
+ curryThunkTy, knownOpened->second -> getGenericEnvironment () )
1963
1966
->castTo <FunctionType>();
1964
1967
}
1965
1968
}
0 commit comments