diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index d8ae74a35fe0e..b86e20d90c357 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -8804,12 +8804,21 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second, // This constraint only exists to vend bindings. auto *packEnv = DC->getGenericEnvironmentOfContext(); - if ((!elementType->hasElementArchetype() && packType->isEqual(elementType)) || - packType->isEqual(packEnv->mapElementTypeIntoPackContext(elementType))) { + + // Map element archetypes to the pack context to check for equality. + if (elementType->hasElementArchetype()) { + auto mappedPack = packEnv->mapElementTypeIntoPackContext(elementType); + return (packType->isEqual(mappedPack) ? + SolutionKind::Solved : SolutionKind::Error); + } + + // Pack expansions can have concrete pattern types. In this case, the pack + // type and element type will be equal. + if (packType->isEqual(elementType)) { return SolutionKind::Solved; - } else { - return SolutionKind::Error; } + + return SolutionKind::Error; } static bool isForKeyPathSubscript(ConstraintSystem &cs, diff --git a/test/Constraints/pack-expansion-expressions.swift b/test/Constraints/pack-expansion-expressions.swift index fe03b591c53b1..2f86baeb740e0 100644 --- a/test/Constraints/pack-expansion-expressions.swift +++ b/test/Constraints/pack-expansion-expressions.swift @@ -117,3 +117,7 @@ func generateTuple() -> (repeat each T) { return (repeat (each T).generate()) } + +func packElementInvalidBinding(_ arg: repeat each T) { + _ = (repeat print(each arg)) +}