@@ -2133,19 +2133,6 @@ static Type typeEraseExistentialSelfReferences(Type refTy, Type baseTy,
21332133
21342134 unsigned metatypeDepth = 0 ;
21352135
2136- // / Check whether the given type has a reference to the generic parameter
2137- // / that we are erasing.
2138- auto hasErasedGenericParameter = [&](Type type) {
2139- if (!type->hasTypeParameter ())
2140- return false ;
2141-
2142- return type.findIf ([&](Type type) {
2143- if (auto gp = type->getAs <GenericTypeParamType>())
2144- return gp->getDepth () == 0 ;
2145- return false ;
2146- });
2147- };
2148-
21492136 std::function<Type (Type, TypePosition)> transformFn;
21502137 transformFn = [&](Type type, TypePosition initialPos) -> Type {
21512138 return type.transformWithPosition (
@@ -2173,7 +2160,7 @@ static Type typeEraseExistentialSelfReferences(Type refTy, Type baseTy,
21732160 if (auto opaque = dyn_cast<OpaqueTypeArchetypeType>(t)) {
21742161 for (auto replacementType :
21752162 opaque->getSubstitutions ().getReplacementTypes ()) {
2176- if (hasErasedGenericParameter ( replacementType)) {
2163+ if (replacementType-> hasTypeParameter ( )) {
21772164 return opaque->getExistentialType ();
21782165 }
21792166 }
@@ -2193,12 +2180,9 @@ static Type typeEraseExistentialSelfReferences(Type refTy, Type baseTy,
21932180 return llvm::None;
21942181 }
21952182
2196- if (t->getRootGenericParam ()->getDepth () > 0 ) {
2197- return Type (t);
2198- }
2183+ assert (t->getRootGenericParam ()->getDepth () == 0 );
21992184
2200- // If the type parameter is beyond the domain of the existential
2201- // generic signature, ignore it.
2185+ // This can happen with invalid code.
22022186 if (!existentialSig->isValidTypeParameter (t)) {
22032187 return Type (t);
22042188 }
0 commit comments