Skip to content

Commit 935edc9

Browse files
committed
AST: Implement TypeBase::getContextSubstitutions() for tuple types
1 parent 67d3ede commit 935edc9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/AST/Type.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4833,8 +4833,30 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
48334833
if (!genericSig)
48344834
return substitutions;
48354835

4836-
// Find the superclass type with the context matching that of the member.
48374836
auto *ownerNominal = dc->getSelfNominalTypeDecl();
4837+
4838+
// If the declaration context is Builtin.TheTupleType or an extension thereof,
4839+
// the base type must be a tuple type. Build a pack type from the tuple's
4840+
// elements and construct a substitution map replacing the generic parameter
4841+
// of Builtin.TheTupleType with the pack.
4842+
if (isa<BuiltinTupleDecl>(ownerNominal)) {
4843+
SmallVector<Type, 2> packElts;
4844+
for (auto type : castTo<TupleType>()->getElementTypes())
4845+
packElts.push_back(type);
4846+
4847+
auto *packType = PackType::get(dc->getASTContext(), packElts);
4848+
4849+
assert(genericSig.getGenericParams().size() == 1);
4850+
auto elementsParam = cast<SubstitutableType>(
4851+
genericSig.getGenericParams()[0]->getCanonicalType());
4852+
substitutions[elementsParam] = packType;
4853+
return substitutions;
4854+
}
4855+
4856+
// If the declaration context is a class or an extension thereof, the base
4857+
// type must be a class, class-constrained archetype, or self-conforming
4858+
// existential with a superclass bound. Get the base type's superclass type
4859+
// for the corresponding declaration context.
48384860
if (auto *ownerClass = dyn_cast<ClassDecl>(ownerNominal)) {
48394861
baseTy = baseTy->getSuperclassForDecl(ownerClass,
48404862
/*usesArchetypes=*/genericEnv != nullptr);

0 commit comments

Comments
 (0)