@@ -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 ());
@@ -3099,8 +3107,15 @@ namespace {
30993107 Type visitPackElementExpr (PackElementExpr *expr) {
31003108 auto packType = CS.getType (expr->getPackRefExpr ());
31013109
3102- if (PackElementEnvironments.empty ())
3103- return Type ();
3110+ // If 'each t' is written outside of a pack expansion expression, allow the
3111+ // type to bind to a hole. The invalid pack reference will be diagnosed when
3112+ // attempting to bind the type variable for the underlying pack reference to
3113+ // a pack type without TVO_CanBindToPack.
3114+ if (PackElementEnvironments.empty ()) {
3115+ return CS.createTypeVariable (CS.getConstraintLocator (expr),
3116+ TVO_CanBindToHole |
3117+ TVO_CanBindToNoEscape);
3118+ }
31043119
31053120 // The type of a PackElementExpr is the opened pack element archetype
31063121 // of the pack reference.
0 commit comments