Skip to content

Commit 55a253a

Browse files
committed
Sema: Variadic generic type aliases don't require runtime support
1 parent 37c8ee2 commit 55a253a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,20 +472,25 @@ static void checkGenericParams(GenericContext *ownerCtx) {
472472
return;
473473

474474
auto *decl = ownerCtx->getAsDecl();
475-
bool isGenericType = isa<GenericTypeDecl>(decl);
475+
bool isGenericType = isa<NominalTypeDecl>(decl);
476476
bool hasPack = false;
477477

478478
for (auto gp : *genericParams) {
479479
// Diagnose generic types with a parameter packs if VariadicGenerics
480480
// is not enabled.
481-
if (gp->isParameterPack() && isGenericType) {
482-
TypeChecker::checkAvailability(
483-
gp->getSourceRange(),
484-
ownerCtx->getASTContext().getVariadicGenericTypeAvailability(),
485-
diag::availability_variadic_type_only_version_newer,
486-
ownerCtx);
487-
488-
if (hasPack) {
481+
if (gp->isParameterPack()) {
482+
// Variadic nominal types require runtime support.
483+
if (isa<NominalTypeDecl>(decl)) {
484+
TypeChecker::checkAvailability(
485+
gp->getSourceRange(),
486+
ownerCtx->getASTContext().getVariadicGenericTypeAvailability(),
487+
diag::availability_variadic_type_only_version_newer,
488+
ownerCtx);
489+
}
490+
491+
// Variadic nominal and type alias types can only have a single
492+
// parameter pack.
493+
if (hasPack && isa<GenericTypeDecl>(decl)) {
489494
gp->diagnose(diag::more_than_one_pack_in_type);
490495
}
491496

test/Generics/variadic_generic_types_availability.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
struct G<each T> {}
66
// expected-note@-1 {{add @available attribute to enclosing generic struct}}
77
// expected-error@-2 {{parameter packs in generic types are only available in macOS 99.99.0 or newer}}
8+
9+
// Type aliases are OK
10+
typealias A<each T> = (repeat each T)

0 commit comments

Comments
 (0)