IDE: Use GenericSignature::getUpperBound()

This commit is contained in:
Slava Pestov
2024-02-01 15:03:37 -05:00
parent 9820d38f7f
commit 9bf51a9d3f
2 changed files with 28 additions and 31 deletions

View File

@@ -87,24 +87,15 @@ Type CompletionOverrideLookup::getOpaqueResultType(
// If it has same type requrement, we will emit the concrete type.
return nullptr;
// Collect requirements on the associatedtype.
SmallVector<Type, 2> opaqueTypes;
bool hasExplicitAnyObject = false;
if (auto superTy = genericSig->getSuperclassBound(ResultT))
opaqueTypes.push_back(superTy);
for (const auto proto : genericSig->getRequiredProtocols(ResultT))
opaqueTypes.push_back(proto->getDeclaredInterfaceType());
if (auto layout = genericSig->getLayoutConstraint(ResultT))
hasExplicitAnyObject = layout->isClass();
auto upperBound = genericSig->getUpperBound(
ResultT,
/*forExistentialSelf=*/false,
/*withParameterizedProtocols=*/false);
if (!hasExplicitAnyObject) {
if (opaqueTypes.empty())
return nullptr;
if (opaqueTypes.size() == 1)
return opaqueTypes.front();
}
return ProtocolCompositionType::get(VD->getASTContext(), opaqueTypes,
hasExplicitAnyObject);
if (upperBound->isAny())
return nullptr;
return upperBound;
}
void CompletionOverrideLookup::addValueOverride(