@@ -4194,7 +4194,16 @@ static void enumerateOptionalConversionRestrictions(
41944194/// Determine whether we can bind the given type variable to the given
41954195/// fixed type.
41964196static 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() ||
41984207 !type->is<DependentMemberType>();
41994208}
42004209
@@ -11492,29 +11501,15 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1149211501
1149311502bool ConstraintSystem::resolvePackExpansion(TypeVariableType *typeVar,
1149411503 Type contextualType) {
11495- auto *locator = typeVar->getImpl().getLocator( );
11504+ assert( typeVar->getImpl().isPackExpansion() );
1149611505
11497- Type openedExpansionType;
11498- if (auto expansionElt =
11499- locator->getLastElementAs<LocatorPathElt::PackExpansionType>()) {
11500- openedExpansionType = expansionElt->getOpenedType();
11501- }
11506+ auto *locator = typeVar->getImpl().getLocator();
1150211507
11503- if (!openedExpansionType)
11504- return false;
11508+ Type openedExpansionType =
11509+ locator->castLastElementTo<LocatorPathElt::PackExpansionType>()
11510+ .getOpenedType();
1150511511
1150611512 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-
1151811513 return true;
1151911514}
1152011515
0 commit comments