AST: Clone generic parameter list of tuple extension from extended typealias

This commit is contained in:
Slava Pestov
2023-08-30 14:00:57 -04:00
parent fd06bd87aa
commit d5cdfb2cf2
9 changed files with 104 additions and 45 deletions

View File

@@ -7861,27 +7861,24 @@ Type DeclContext::getSelfTypeInContext() const {
return mapTypeIntoContext(getSelfInterfaceType());
}
TupleType *BuiltinTupleDecl::getTupleSelfType() const {
if (TupleSelfType)
return TupleSelfType;
TupleType *BuiltinTupleDecl::getTupleSelfType(const ExtensionDecl *owner) const {
auto &ctx = getASTContext();
// Get the generic parameter type 'Elements'.
auto paramType = getGenericParams()->getParams()[0]
->getDeclaredInterfaceType();
// Get the generic parameter type 'each T'.
auto *genericParams = owner->getGenericParams();
assert(genericParams != nullptr);
assert(genericParams->getParams().size() == 1);
assert(genericParams->getOuterParameters() == nullptr);
auto paramType = genericParams->getParams()[0]->getDeclaredInterfaceType();
// Build the pack expansion type 'Elements...'.
// Build the pack expansion type 'repeat each T'.
Type packExpansionType = PackExpansionType::get(paramType, paramType);
// Build the one-element tuple type '(Elements...)'.
// Build the one-element tuple type '(repeat each T)'.
SmallVector<TupleTypeElt, 1> elts;
elts.push_back(packExpansionType);
const_cast<BuiltinTupleDecl *>(this)->TupleSelfType =
TupleType::get(elts, ctx);
return TupleSelfType;
return TupleType::get(elts, ctx);
}
/// Retrieve the interface type of 'self' for the given context.
@@ -7890,7 +7887,7 @@ Type DeclContext::getSelfInterfaceType() const {
if (auto *nominalDecl = getSelfNominalTypeDecl()) {
if (auto *builtinTupleDecl = dyn_cast<BuiltinTupleDecl>(nominalDecl))
return builtinTupleDecl->getTupleSelfType();
return builtinTupleDecl->getTupleSelfType(cast<ExtensionDecl>(this));
if (isa<ProtocolDecl>(nominalDecl)) {
auto *genericParams = nominalDecl->getGenericParams();