@@ -4194,7 +4194,16 @@ static void enumerateOptionalConversionRestrictions(
4194
4194
/// Determine whether we can bind the given type variable to the given
4195
4195
/// fixed type.
4196
4196
static bool isBindable(TypeVariableType *typeVar, Type type) {
4197
- return !ConstraintSystem::typeVarOccursInType(typeVar, type) &&
4197
+ // Disallow recursive bindings.
4198
+ if (ConstraintSystem::typeVarOccursInType(typeVar, type))
4199
+ return false;
4200
+
4201
+ // If type variable we are about to bind represents a pack
4202
+ // expansion type, allow the binding to happen regardless of
4203
+ // what the \c type is, because contextual type is just a hint
4204
+ // in this situation and type variable would be bound to its
4205
+ // opened type instead.
4206
+ return typeVar->getImpl().isPackExpansion() ||
4198
4207
!type->is<DependentMemberType>();
4199
4208
}
4200
4209
@@ -11492,29 +11501,15 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
11492
11501
11493
11502
bool ConstraintSystem::resolvePackExpansion(TypeVariableType *typeVar,
11494
11503
Type contextualType) {
11495
- auto *locator = typeVar->getImpl().getLocator( );
11504
+ assert( typeVar->getImpl().isPackExpansion() );
11496
11505
11497
- Type openedExpansionType;
11498
- if (auto expansionElt =
11499
- locator->getLastElementAs<LocatorPathElt::PackExpansionType>()) {
11500
- openedExpansionType = expansionElt->getOpenedType();
11501
- }
11506
+ auto *locator = typeVar->getImpl().getLocator();
11502
11507
11503
- if (!openedExpansionType)
11504
- return false;
11508
+ Type openedExpansionType =
11509
+ locator->castLastElementTo<LocatorPathElt::PackExpansionType>()
11510
+ .getOpenedType();
11505
11511
11506
11512
assignFixedType(typeVar, openedExpansionType, locator);
11507
-
11508
- // We have a fully resolved contextual pack expansion type, let's
11509
- // apply it right away.
11510
- if (!contextualType->isEqual(openedExpansionType)) {
11511
- assert(contextualType->is<PackExpansionType>() &&
11512
- !contextualType->hasTypeVariable());
11513
- auto result = matchTypes(openedExpansionType, contextualType,
11514
- ConstraintKind::Equal, {}, locator);
11515
- return !result.isFailure();
11516
- }
11517
-
11518
11513
return true;
11519
11514
}
11520
11515
0 commit comments