Skip to content

Commit fc05c00

Browse files
committed
Fix the pretty-printing of pack expansion types to match the current design
1 parent 43da3fd commit fc05c00

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ struct PrintOptions {
285285

286286
bool PrintImplicitAttrs = true;
287287

288+
/// Whether to print the \c each keyword for pack archetypes.
289+
bool PrintExplicitEach = false;
290+
288291
/// Whether to print the \c any keyword for existential
289292
/// types.
290293
bool PrintExplicitAny = false;

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,6 +5416,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
54165416
} else if (auto existential = dyn_cast<ExistentialMetatypeType>(T.getPointer())) {
54175417
if (!Options.PrintExplicitAny)
54185418
return isSimpleUnderPrintOptions(existential->getInstanceType());
5419+
} else if (isa<PackArchetypeType>(T.getPointer())) {
5420+
return !Options.PrintExplicitEach;
54195421
}
54205422
return T->hasSimpleTypeRepr();
54215423
}
@@ -5731,8 +5733,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
57315733
}
57325734

57335735
void visitPackExpansionType(PackExpansionType *T) {
5734-
visit(T->getPatternType());
5735-
Printer << "...";
5736+
PrintOptions innerOptions = Options;
5737+
innerOptions.PrintExplicitEach = true;
5738+
5739+
Printer << "repeat ";
5740+
TypePrinter(Printer, innerOptions).visit(T->getPatternType());
57365741
}
57375742

57385743
void visitTupleType(TupleType *T) {
@@ -6679,6 +6684,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
66796684
}
66806685

66816686
void visitPackArchetypeType(PackArchetypeType *T) {
6687+
if (Options.PrintExplicitEach)
6688+
Printer << "each ";
66826689
printArchetypeCommon(T);
66836690
}
66846691

0 commit comments

Comments
 (0)