@@ -4210,7 +4210,16 @@ static void enumerateOptionalConversionRestrictions(
4210
4210
/// Determine whether we can bind the given type variable to the given
4211
4211
/// fixed type.
4212
4212
static bool isBindable(TypeVariableType *typeVar, Type type) {
4213
- return !ConstraintSystem::typeVarOccursInType(typeVar, type) &&
4213
+ // Disallow recursive bindings.
4214
+ if (ConstraintSystem::typeVarOccursInType(typeVar, type))
4215
+ return false;
4216
+
4217
+ // If type variable we are about to bind represents a pack
4218
+ // expansion type, allow the binding to happen regardless of
4219
+ // what the \c type is, because contextual type is just a hint
4220
+ // in this situation and type variable would be bound to its
4221
+ // opened type instead.
4222
+ return typeVar->getImpl().isPackExpansion() ||
4214
4223
!type->is<DependentMemberType>();
4215
4224
}
4216
4225
@@ -11621,29 +11630,15 @@ bool ConstraintSystem::resolveKeyPath(TypeVariableType *typeVar,
11621
11630
11622
11631
bool ConstraintSystem::resolvePackExpansion(TypeVariableType *typeVar,
11623
11632
Type contextualType) {
11624
- auto *locator = typeVar->getImpl().getLocator( );
11633
+ assert( typeVar->getImpl().isPackExpansion() );
11625
11634
11626
- Type openedExpansionType;
11627
- if (auto expansionElt =
11628
- locator->getLastElementAs<LocatorPathElt::PackExpansionType>()) {
11629
- openedExpansionType = expansionElt->getOpenedType();
11630
- }
11635
+ auto *locator = typeVar->getImpl().getLocator();
11631
11636
11632
- if (!openedExpansionType)
11633
- return false;
11637
+ Type openedExpansionType =
11638
+ locator->castLastElementTo<LocatorPathElt::PackExpansionType>()
11639
+ .getOpenedType();
11634
11640
11635
11641
assignFixedType(typeVar, openedExpansionType, locator);
11636
-
11637
- // We have a fully resolved contextual pack expansion type, let's
11638
- // apply it right away.
11639
- if (!contextualType->isEqual(openedExpansionType)) {
11640
- assert(contextualType->is<PackExpansionType>() &&
11641
- !contextualType->hasTypeVariable());
11642
- auto result = matchTypes(openedExpansionType, contextualType,
11643
- ConstraintKind::Equal, {}, locator);
11644
- return !result.isFailure();
11645
- }
11646
-
11647
11642
return true;
11648
11643
}
11649
11644
0 commit comments