@@ -3559,12 +3559,31 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
3559
3559
elementOptions = elementOptions.withoutContext (true );
3560
3560
}
3561
3561
3562
- // Variadic tuples are not permitted.
3563
3562
bool complained = false ;
3564
3563
if (repr->hasEllipsis ()) {
3565
- diagnose (repr->getEllipsisLoc (), diag::tuple_ellipsis);
3566
- repr->removeEllipsis ();
3567
- complained = true ;
3564
+ if (repr->getNumElements () == 1 && !repr->hasElementNames ()) {
3565
+ // This is probably a pack expansion. Try to resolve the pattern type.
3566
+ auto patternTy = resolveType (repr->getElementType (0 ), elementOptions);
3567
+ if (patternTy->hasError ())
3568
+ complained = true ;
3569
+
3570
+ // If there's no reference to a variadic generic parameter, complain
3571
+ // - the pack won't actually expand to anything meaningful.
3572
+ if (!patternTy->hasTypeSequence ())
3573
+ diagnose (repr->getLoc (), diag::expansion_not_variadic, patternTy)
3574
+ .highlight (repr->getParens ());
3575
+
3576
+ return PackExpansionType::get (patternTy);
3577
+ } else {
3578
+ // Variadic tuples are not permitted.
3579
+ //
3580
+ // FIXME: We could probably make this work.
3581
+ // (T, U, V...) is a reasonable pack expansion to support with a kind of
3582
+ // "guaranteed bound" of at least two elements.
3583
+ diagnose (repr->getEllipsisLoc (), diag::tuple_ellipsis);
3584
+ repr->removeEllipsis ();
3585
+ complained = true ;
3586
+ }
3568
3587
}
3569
3588
3570
3589
bool hadError = false ;
0 commit comments