@@ -127,6 +127,14 @@ static bool isPackExpansionType(Type type) {
127127 return false;
128128}
129129
130+ bool constraints::isSingleUnlabeledPackExpansionTuple(Type type) {
131+ auto *tuple = type->getRValueType()->getAs<TupleType>();
132+ // TODO: drop no name requirement
133+ return tuple && (tuple->getNumElements() == 1) &&
134+ isPackExpansionType(tuple->getElementType(0)) &&
135+ !tuple->getElement(0).hasName();
136+ }
137+
130138static bool containsPackExpansionType(ArrayRef<AnyFunctionType::Param> params) {
131139 return llvm::any_of(params, [&](const auto ¶m) {
132140 return isPackExpansionType(param.getPlainType());
@@ -9121,6 +9129,16 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
91219129 return SolutionKind::Solved;
91229130 }
91239131
9132+ if (isSingleUnlabeledPackExpansionTuple(patternType)) {
9133+ auto *elementVar =
9134+ createTypeVariable(getConstraintLocator(locator), /*options=*/0);
9135+ addValueMemberConstraint(
9136+ patternType, DeclNameRef(getASTContext().Id_element), elementVar, DC,
9137+ FunctionRefKind::Unapplied, {},
9138+ getConstraintLocator(locator, {ConstraintLocator::Member}));
9139+ patternType = elementVar;
9140+ }
9141+
91249142 // Let's try to resolve element type based on the pattern type.
91259143 if (!patternType->hasTypeVariable()) {
91269144 auto *loc = getConstraintLocator(locator);
@@ -9338,6 +9356,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
93389356 if (!memberName.isSpecial()) {
93399357 StringRef nameStr = memberName.getBaseIdentifier().str();
93409358 // Accessing `.element` on an abstract tuple materializes a pack.
9359+ // (deprecated behavior)
93419360 if (nameStr == "element" && baseTuple->getNumElements() == 1 &&
93429361 isPackExpansionType(baseTuple->getElementType(0))) {
93439362 auto elementType = baseTuple->getElementType(0);
@@ -13312,6 +13331,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyShapeOfConstraint(
1331213331 return SolutionKind::Solved;
1331313332 }
1331413333
13334+ // Map element archetypes to the pack context to check for equality.
13335+ if (packTy->hasElementArchetype()) {
13336+ auto *packEnv = DC->getGenericEnvironmentOfContext();
13337+ packTy = packEnv->mapElementTypeIntoPackContext(packTy);
13338+ }
13339+
1331513340 auto shape = packTy->getReducedShape();
1331613341 addConstraint(ConstraintKind::Bind, shapeTy, shape, locator);
1331713342 return SolutionKind::Solved;
0 commit comments