@@ -1416,13 +1416,20 @@ namespace {
1416
1416
Type
1417
1417
resolveTypeReferenceInExpression (TypeRepr *repr, TypeResolverContext resCtx,
1418
1418
const ConstraintLocatorBuilder &locator) {
1419
+ TypeResolutionOptions options (resCtx);
1420
+
1419
1421
// Introduce type variables for unbound generics.
1420
1422
const auto genericOpener = OpenUnboundGenericType (CS, locator);
1421
1423
const auto placeholderHandler = HandlePlaceholderType (CS, locator);
1422
- // FIXME: Open pack elements with a PackElementOf constraint.
1423
1424
OpenPackElementFn packElementOpener = nullptr ;
1425
+ if (!PackElementEnvironments.empty ()) {
1426
+ options |= TypeResolutionFlags::AllowPackReferences;
1427
+ packElementOpener = OpenPackElementType (CS,
1428
+ CS.getConstraintLocator (locator), PackElementEnvironments.back ());
1429
+ }
1430
+
1424
1431
const auto result = TypeResolution::resolveContextualType (
1425
- repr, CS.DC , resCtx , genericOpener, placeholderHandler,
1432
+ repr, CS.DC , options , genericOpener, placeholderHandler,
1426
1433
packElementOpener);
1427
1434
if (result->hasError ()) {
1428
1435
CS.recordFix (
@@ -1662,16 +1669,20 @@ namespace {
1662
1669
ArrayRef<TypeRepr *> specializationArgs) {
1663
1670
// Resolve each type.
1664
1671
SmallVector<Type, 2 > specializationArgTypes;
1665
- const auto options =
1672
+ auto options =
1666
1673
TypeResolutionOptions (TypeResolverContext::InExpression);
1667
1674
for (auto specializationArg : specializationArgs) {
1675
+ OpenPackElementFn packElementOpener = nullptr ;
1676
+ if (!PackElementEnvironments.empty ()) {
1677
+ options |= TypeResolutionFlags::AllowPackReferences;
1678
+ packElementOpener = OpenPackElementType (CS, locator, PackElementEnvironments.back ());
1679
+ }
1668
1680
const auto result = TypeResolution::resolveContextualType (
1669
1681
specializationArg, CurDC, options,
1670
1682
// Introduce type variables for unbound generics.
1671
1683
OpenUnboundGenericType (CS, locator),
1672
1684
HandlePlaceholderType (CS, locator),
1673
- // FIXME: Open pack elements with a PackElementOf constraint.
1674
- /* packElementOpener*/ nullptr );
1685
+ packElementOpener);
1675
1686
if (result->hasError ())
1676
1687
return true ;
1677
1688
@@ -1728,16 +1739,21 @@ namespace {
1728
1739
// Bind the specified generic arguments to the type variables in the
1729
1740
// open type.
1730
1741
auto *const locator = CS.getConstraintLocator (expr);
1731
- const auto options =
1742
+ auto options =
1732
1743
TypeResolutionOptions (TypeResolverContext::InExpression);
1733
1744
for (size_t i = 0 , e = specializations.size (); i < e; ++i) {
1745
+ OpenPackElementFn packElementOpener = nullptr ;
1746
+ if (!PackElementEnvironments.empty ()) {
1747
+ options |= TypeResolutionFlags::AllowPackReferences;
1748
+ packElementOpener = OpenPackElementType (CS, locator, PackElementEnvironments.back ());
1749
+ }
1750
+
1734
1751
const auto result = TypeResolution::resolveContextualType (
1735
1752
specializations[i], CS.DC , options,
1736
1753
// Introduce type variables for unbound generics.
1737
1754
OpenUnboundGenericType (CS, locator),
1738
1755
HandlePlaceholderType (CS, locator),
1739
- // FIXME: Open pack elements with a PackElementOf constraint.
1740
- /* packElementOpener*/ nullptr );
1756
+ packElementOpener);
1741
1757
if (result->hasError ())
1742
1758
return Type ();
1743
1759
@@ -3001,18 +3017,12 @@ namespace {
3001
3017
3002
3018
Type visitPackElementExpr (PackElementExpr *expr) {
3003
3019
auto packType = CS.getType (expr->getPackRefExpr ());
3004
- auto *elementType =
3005
- CS.createTypeVariable (CS.getConstraintLocator (expr),
3006
- TVO_CanBindToHole);
3007
- auto *elementEnv = PackElementEnvironments.back ();
3008
- auto *elementLoc = CS.getConstraintLocator (
3009
- expr, LocatorPathElt::OpenedPackElement (elementEnv));
3010
3020
3011
3021
// The type of a PackElementExpr is the opened pack element archetype
3012
3022
// of the pack reference.
3013
- CS. addConstraint (ConstraintKind::PackElementOf, elementType, packType ,
3014
- elementLoc );
3015
- return elementType ;
3023
+ OpenPackElementType openPackElement (CS, CS. getConstraintLocator (expr) ,
3024
+ PackElementEnvironments. back () );
3025
+ return openPackElement (packType) ;
3016
3026
}
3017
3027
3018
3028
Type visitDynamicTypeExpr (DynamicTypeExpr *expr) {
0 commit comments