@@ -9626,6 +9626,49 @@ ConstraintSystem::simplifyBindTupleOfFunctionParamsConstraint(
9626
9626
return SolutionKind::Solved;
9627
9627
}
9628
9628
9629
+ ConstraintSystem::SolutionKind
9630
+ ConstraintSystem::matchPackElementType(Type elementType, Type patternType,
9631
+ ConstraintLocatorBuilder locator) {
9632
+ auto *loc = getConstraintLocator(locator);
9633
+ auto shapeClass = patternType->getReducedShape();
9634
+ auto *elementEnv = getPackElementEnvironment(loc, shapeClass);
9635
+
9636
+ // Without an opened element environment, we cannot derive the
9637
+ // element binding.
9638
+ if (!elementEnv) {
9639
+ if (!shouldAttemptFixes())
9640
+ return SolutionKind::Error;
9641
+
9642
+ // `each` was applied to a concrete type.
9643
+ if (!shapeClass->is<PackArchetypeType>()) {
9644
+ if (recordFix(AllowInvalidPackElement::create(*this, patternType, loc)))
9645
+ return SolutionKind::Error;
9646
+ } else {
9647
+ auto envShape = PackExpansionEnvironments.find(loc);
9648
+ if (envShape == PackExpansionEnvironments.end()) {
9649
+ return SolutionKind::Error;
9650
+ }
9651
+ auto *fix = SkipSameShapeRequirement::create(
9652
+ *this, envShape->second.second, shapeClass,
9653
+ getConstraintLocator(loc, ConstraintLocator::PackShape));
9654
+ if (recordFix(fix)) {
9655
+ return SolutionKind::Error;
9656
+ }
9657
+ }
9658
+
9659
+ recordAnyTypeVarAsPotentialHole(elementType);
9660
+ return SolutionKind::Solved;
9661
+ }
9662
+
9663
+ auto expectedElementTy =
9664
+ elementEnv->mapContextualPackTypeIntoElementContext(patternType);
9665
+ assert(!expectedElementTy->is<PackType>());
9666
+
9667
+ addConstraint(ConstraintKind::Equal, elementType, expectedElementTy,
9668
+ locator);
9669
+ return SolutionKind::Solved;
9670
+ }
9671
+
9629
9672
ConstraintSystem::SolutionKind
9630
9673
ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
9631
9674
TypeMatchOptions flags,
@@ -9660,46 +9703,8 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
9660
9703
}
9661
9704
9662
9705
// Let's try to resolve element type based on the pattern type.
9663
- if (!patternType->hasTypeVariable()) {
9664
- auto *loc = getConstraintLocator(locator);
9665
- auto shapeClass = patternType->getReducedShape();
9666
- auto *elementEnv = getPackElementEnvironment(loc, shapeClass);
9667
-
9668
- // Without an opened element environment, we cannot derive the
9669
- // element binding.
9670
- if (!elementEnv) {
9671
- if (!shouldAttemptFixes())
9672
- return SolutionKind::Error;
9673
-
9674
- // `each` was applied to a concrete type.
9675
- if (!shapeClass->is<PackArchetypeType>()) {
9676
- if (recordFix(AllowInvalidPackElement::create(*this, patternType, loc)))
9677
- return SolutionKind::Error;
9678
- } else {
9679
- auto envShape = PackExpansionEnvironments.find(loc);
9680
- if (envShape == PackExpansionEnvironments.end()) {
9681
- return SolutionKind::Error;
9682
- }
9683
- auto *fix = SkipSameShapeRequirement::create(
9684
- *this, envShape->second.second, shapeClass,
9685
- getConstraintLocator(loc, ConstraintLocator::PackShape));
9686
- if (recordFix(fix)) {
9687
- return SolutionKind::Error;
9688
- }
9689
- }
9690
-
9691
- recordAnyTypeVarAsPotentialHole(elementType);
9692
- return SolutionKind::Solved;
9693
- }
9694
-
9695
- auto expectedElementTy =
9696
- elementEnv->mapContextualPackTypeIntoElementContext(patternType);
9697
- assert(!expectedElementTy->is<PackType>());
9698
-
9699
- addConstraint(ConstraintKind::Equal, elementType, expectedElementTy,
9700
- locator);
9701
- return SolutionKind::Solved;
9702
- }
9706
+ if (!patternType->hasTypeVariable())
9707
+ return matchPackElementType(elementType, patternType, locator);
9703
9708
9704
9709
// Otherwise we are inferred or checking pattern type.
9705
9710
0 commit comments