File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -2759,7 +2759,8 @@ DestructureTupleToMatchPackExpansionParameter::create(
2759
2759
2760
2760
bool AllowValueExpansionWithoutPackReferences::diagnose (
2761
2761
const Solution &solution, bool asNote) const {
2762
- return false ;
2762
+ ValuePackExpansionWithoutPackReferences failure (solution, getLocator ());
2763
+ return failure.diagnose (asNote);
2763
2764
}
2764
2765
2765
2766
AllowValueExpansionWithoutPackReferences *
Original file line number Diff line number Diff line change @@ -3080,6 +3080,12 @@ namespace {
3080
3080
// pack expansion expression through the shape type variable.
3081
3081
SmallVector<ASTNode, 2 > expandedPacks;
3082
3082
expr->getExpandedPacks (expandedPacks);
3083
+
3084
+ if (expandedPacks.empty ()) {
3085
+ (void )CS.recordFix (AllowValueExpansionWithoutPackReferences::create (
3086
+ CS, CS.getConstraintLocator (expr)));
3087
+ }
3088
+
3083
3089
for (auto pack : expandedPacks) {
3084
3090
Type packType;
3085
3091
if (auto *elementExpr = getAsExpr<PackElementExpr>(pack)) {
Original file line number Diff line number Diff line change @@ -457,3 +457,26 @@ do {
457
457
// expected-error@-1 {{pack reference 'each T' can only appear in pack expansion}}
458
458
}
459
459
}
460
+
461
+ // rdar://107835215 - failed to produce a diagnostic for invalid pack expansion expression
462
+ do {
463
+ func test1( x: Int ) {
464
+ repeat x
465
+ // expected-error@-1:5 {{value pack expansion must contain at least one pack reference}}
466
+ }
467
+
468
+ func test2< T: Numeric > ( _ x: T ) {
469
+ repeat print( x * 2 )
470
+ // expected-error@-1:5 {{value pack expansion must contain at least one pack reference}}
471
+ }
472
+
473
+ struct S < T> {
474
+ init ( _: T ) { }
475
+ }
476
+
477
+ func test< each T > ( x: repeat each T , y: Int ) {
478
+ func f< each A , each B > ( _: repeat each A , y: repeat each B ) { }
479
+ f ( repeat each x, y: repeat [ S ( y) ] )
480
+ // expected-error@-1:25 {{value pack expansion must contain at least one pack reference}}
481
+ }
482
+ }
You can’t perform that action at this time.
0 commit comments