@@ -923,9 +923,14 @@ namespace {
923923 CS.getConstraintLocator (expr, ConstraintLocator::Member),
924924 TVO_CanBindToHole);
925925 }
926+ unsigned options = (TVO_CanBindToLValue |
927+ TVO_CanBindToNoEscape);
928+ if (!PackElementEnvironments.empty ())
929+ options |= TVO_CanBindToPack;
930+
926931 auto tv = CS.createTypeVariable (
927932 CS.getConstraintLocator (expr, ConstraintLocator::Member),
928- TVO_CanBindToLValue | TVO_CanBindToNoEscape );
933+ options );
929934 SmallVector<OverloadChoice, 4 > outerChoices;
930935 for (auto decl : outerAlternatives) {
931936 outerChoices.push_back (OverloadChoice (Type (), decl, functionRefKind));
@@ -1419,11 +1424,14 @@ namespace {
14191424 return invalidateReference ();
14201425 }
14211426
1427+ unsigned options = (TVO_CanBindToLValue |
1428+ TVO_CanBindToNoEscape);
1429+ if (!PackElementEnvironments.empty ())
1430+ options |= TVO_CanBindToPack;
1431+
14221432 // Create an overload choice referencing this declaration and immediately
14231433 // resolve it. This records the overload for use later.
1424- auto tv = CS.createTypeVariable (locator,
1425- TVO_CanBindToLValue |
1426- TVO_CanBindToNoEscape);
1434+ auto tv = CS.createTypeVariable (locator, options);
14271435
14281436 OverloadChoice choice =
14291437 OverloadChoice (Type (), E->getDecl (), E->getFunctionRefKind ());
@@ -3097,8 +3105,15 @@ namespace {
30973105 Type visitPackElementExpr (PackElementExpr *expr) {
30983106 auto packType = CS.getType (expr->getPackRefExpr ());
30993107
3100- if (PackElementEnvironments.empty ())
3101- return Type ();
3108+ // If 'each t' is written outside of a pack expansion expression, allow the
3109+ // type to bind to a hole. The invalid pack reference will be diagnosed when
3110+ // attempting to bind the type variable for the underlying pack reference to
3111+ // a pack type without TVO_CanBindToPack.
3112+ if (PackElementEnvironments.empty ()) {
3113+ return CS.createTypeVariable (CS.getConstraintLocator (expr),
3114+ TVO_CanBindToHole |
3115+ TVO_CanBindToNoEscape);
3116+ }
31023117
31033118 // The type of a PackElementExpr is the opened pack element archetype
31043119 // of the pack reference.
0 commit comments