@@ -4287,6 +4287,15 @@ ConstraintSystem::matchTypesBindTypeVar(
4287
4287
}
4288
4288
}
4289
4289
4290
+ if (typeVar->getImpl().isPackExpansion()) {
4291
+ if (!flags.contains(TMF_BindingTypeVariable))
4292
+ return formUnsolvedResult();
4293
+
4294
+ return resolvePackExpansion(typeVar, locator)
4295
+ ? getTypeMatchSuccess()
4296
+ : getTypeMatchFailure(locator);
4297
+ }
4298
+
4290
4299
// If we're attempting to bind a PackType or PackArchetypeType to a type
4291
4300
// variable that doesn't support it, we have a pack reference outside of a
4292
4301
// pack expansion expression.
@@ -4305,11 +4314,6 @@ ConstraintSystem::matchTypesBindTypeVar(
4305
4314
type = PlaceholderType::get(typeVar->getASTContext(), typeVar);
4306
4315
}
4307
4316
4308
- // FIXME: Add a fix for this.
4309
- if (typeVar->getImpl().isPackExpansion() && !type->is<PackExpansionType>()) {
4310
- return getTypeMatchFailure(locator);
4311
- }
4312
-
4313
4317
// Binding to a pack expansion type is always an error in Swift 6 mode.
4314
4318
// This indicates that a pack expansion expression was used in a context
4315
4319
// that doesn't support it.
@@ -11229,6 +11233,29 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
11229
11233
return !generateConstraints(AnyFunctionRef{closure}, closure->getBody());
11230
11234
}
11231
11235
11236
+ bool ConstraintSystem::resolvePackExpansion(TypeVariableType *typeVar,
11237
+ ConstraintLocatorBuilder locator) {
11238
+ // TODO: Pack expansion type variable can carry opened type.
11239
+ auto expansion =
11240
+ llvm::find_if(OpenedPackExpansionTypes, [&](const auto &expansion) {
11241
+ return expansion.second->isEqual(typeVar);
11242
+ });
11243
+
11244
+ assert(expansion != OpenedPackExpansionTypes.end());
11245
+
11246
+ assignFixedType(typeVar, expansion->first, getConstraintLocator(locator));
11247
+
11248
+ if (isDebugMode()) {
11249
+ PrintOptions PO;
11250
+ PO.PrintTypesForDebugging = true;
11251
+ llvm::errs().indent(solverState->getCurrentIndent())
11252
+ << "(pack expansion variable " << typeVar->getString(PO)
11253
+ << " is bound to '" << expansion->first->getString(PO) << "')\n";
11254
+ }
11255
+
11256
+ return true;
11257
+ }
11258
+
11232
11259
ConstraintSystem::SolutionKind
11233
11260
ConstraintSystem::simplifyDynamicTypeOfConstraint(
11234
11261
Type type1, Type type2,
0 commit comments