Skip to content

Commit fec6c06

Browse files
committed
AST: TupleType::get() asserts if pack expansion type is followed by an unlabeled element
1 parent b9662f1 commit fec6c06

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,6 +3135,15 @@ TupleType *TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
31353135
properties |= eltTy->getRecursiveProperties();
31363136
}
31373137

3138+
// Enforce an invariant.
3139+
for (unsigned i = 0, e = Fields.size(); i < e; ++i) {
3140+
if (Fields[i].getType()->is<PackExpansionType>()) {
3141+
assert(i == e - 1 || Fields[i + 1].hasName() &&
3142+
"Tuple element with pack expansion type cannot be followed "
3143+
"by an unlabeled element");
3144+
}
3145+
}
3146+
31383147
auto arena = getArena(properties);
31393148

31403149
void *InsertPos = nullptr;

lib/AST/Type.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5702,9 +5702,16 @@ case TypeKind::Id:
57025702
anyChanged = true;
57035703
}
57045704

5705+
// "Splat" the elements of the transformed pack expansion into the tuple.
57055706
if (auto *transformedPack = transformedEltTy->getAs<PackType>()) {
5706-
elements.append(transformedPack->getElementTypes().begin(),
5707-
transformedPack->getElementTypes().end());
5707+
auto transformedEltTypes = transformedPack->getElementTypes();
5708+
if (!transformedEltTypes.empty()) {
5709+
// Keep the label on the first element.
5710+
5711+
elements.push_back(elt.getWithType(transformedEltTypes.front()));
5712+
elements.append(transformedEltTypes.begin() + 1,
5713+
transformedEltTypes.end());
5714+
}
57085715
} else {
57095716
// Add the new tuple element, with the transformed type.
57105717
elements.push_back(elt.getWithType(transformedEltTy));

0 commit comments

Comments
 (0)