Skip to content

Commit d16fed6

Browse files
committed
The canonical type of a pack expansion has a reduced shape.
1 parent 3b3e53e commit d16fed6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/AST/ASTContext.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3272,8 +3272,19 @@ PackExpansionType *PackExpansionType::get(Type patternType, Type countType) {
32723272
.PackExpansionTypes.FindNodeOrInsertPos(id, insertPos))
32733273
return expType;
32743274

3275+
// The canonical pack expansion type uses the canonical shape.
3276+
// For interface types, we'd need a signature to do this properly,
3277+
// but for archetypes we can do it directly.
3278+
bool countIsCanonical = countType->isCanonical();
3279+
if (countIsCanonical) {
3280+
if (auto archetype = dyn_cast<PackArchetypeType>(countType.getPointer())) {
3281+
auto reducedShape = archetype->getReducedShape();
3282+
countIsCanonical = (reducedShape.getPointer() == archetype);
3283+
}
3284+
}
3285+
32753286
const ASTContext *canCtx =
3276-
(patternType->isCanonical() && countType->isCanonical())
3287+
(patternType->isCanonical() && countIsCanonical)
32773288
? &context : nullptr;
32783289
PackExpansionType *expansionType =
32793290
new (context, arena) PackExpansionType(patternType, countType, properties,

lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,8 @@ CanType TypeBase::computeCanonicalType() {
16731673
auto *expansion = cast<PackExpansionType>(this);
16741674
auto patternType = expansion->getPatternType()->getCanonicalType();
16751675
auto countType = expansion->getCountType()->getCanonicalType();
1676+
if (auto packArchetype = dyn_cast<PackArchetypeType>(countType))
1677+
countType = packArchetype->getReducedShape();
16761678
Result = PackExpansionType::get(patternType, countType);
16771679
break;
16781680
}

0 commit comments

Comments
 (0)