@@ -1118,6 +1118,16 @@ Type ConstraintSystem::getFixedTypeRecursive(Type type,
11181118 return getFixedTypeRecursive (newType, flags, wantRValue);
11191119 }
11201120
1121+ // Tuple types can lose their tuple structure under substitution
1122+ // when a parameter pack is substituted with one element.
1123+ if (auto tuple = type->getAs <TupleType>()) {
1124+ auto simplified = simplifyType (type);
1125+ if (simplified.getPointer () == type.getPointer ())
1126+ return type;
1127+
1128+ return getFixedTypeRecursive (simplified, flags, wantRValue);
1129+ }
1130+
11211131 if (auto typeVar = type->getAs <TypeVariableType>()) {
11221132 if (auto fixed = getFixedType (typeVar))
11231133 return getFixedTypeRecursive (fixed, flags, wantRValue);
@@ -3702,6 +3712,20 @@ Type ConstraintSystem::simplifyTypeImpl(Type type,
37023712 if (auto tvt = dyn_cast<TypeVariableType>(type.getPointer ()))
37033713 return getFixedTypeFn (tvt);
37043714
3715+ if (auto tuple = dyn_cast<TupleType>(type.getPointer ())) {
3716+ if (tuple->getNumElements () == 1 ) {
3717+ auto element = tuple->getElement (0 );
3718+ auto elementType = simplifyTypeImpl (element.getType (), getFixedTypeFn);
3719+
3720+ // Flatten single-element tuples containing type variables that cannot
3721+ // bind to packs.
3722+ auto typeVar = elementType->getAs <TypeVariableType>();
3723+ if (!element.hasName () && typeVar && !typeVar->getImpl ().canBindToPack ()) {
3724+ return typeVar;
3725+ }
3726+ }
3727+ }
3728+
37053729 // If this is a dependent member type for which we end up simplifying
37063730 // the base to a non-type-variable, perform lookup.
37073731 if (auto depMemTy = dyn_cast<DependentMemberType>(type.getPointer ())) {
0 commit comments