Skip to content

Commit ebcd444

Browse files
committed
[ASTVerifier] Move PackExpansionType::get assertions into the ASTVerifier.
These assertions are violated for invalid code, so let's only check these on a well-formed AST.
1 parent e063f02 commit ebcd444

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,17 +3247,7 @@ PackExpansionType::PackExpansionType(Type patternType, Type countType,
32473247
RecursiveTypeProperties properties,
32483248
const ASTContext *canCtx)
32493249
: TypeBase(TypeKind::PackExpansion, canCtx, properties),
3250-
patternType(patternType), countType(countType) {
3251-
3252-
// TODO: it would be nice if the solver didn't stick PlaceholderTypes and
3253-
// UnresolvedTypes in here.
3254-
assert(countType->is<PackType>() ||
3255-
countType->is<TypeVariableType>() ||
3256-
countType->is<PackArchetypeType>() ||
3257-
countType->is<PlaceholderType>() ||
3258-
countType->is<UnresolvedType>() ||
3259-
countType->castTo<GenericTypeParamType>()->isParameterPack());
3260-
}
3250+
patternType(patternType), countType(countType) {}
32613251

32623252
CanPackExpansionType
32633253
CanPackExpansionType::get(CanType patternType, CanType countType) {

lib/AST/ASTVerifier.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,18 @@ class Verifier : public ASTWalker {
603603
abort();
604604
}
605605

606+
// Check for invalid pack expansion shape types.
607+
if (auto *expansion = type->getAs<PackExpansionType>()) {
608+
auto countType = expansion->getCountType();
609+
if (!(countType->is<PackType>() ||
610+
countType->is<PackArchetypeType>() ||
611+
(countType->is<GenericTypeParamType>() &&
612+
countType->castTo<GenericTypeParamType>()->isParameterPack()))) {
613+
Out << "non-pack shape type" << countType->getString() << "\n";
614+
abort();
615+
}
616+
}
617+
606618
if (!type->hasArchetype())
607619
return;
608620

0 commit comments

Comments
 (0)