Skip to content

Commit 1715a1e

Browse files
authored
Merge pull request #64110 from hborla/pack-element-of-crash
[ConstraintSystem] Handle invalid pack element bindings during `PackElementOf` simplification.
2 parents 221c727 + e063f02 commit 1715a1e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8804,12 +8804,21 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
88048804

88058805
// This constraint only exists to vend bindings.
88068806
auto *packEnv = DC->getGenericEnvironmentOfContext();
8807-
if ((!elementType->hasElementArchetype() && packType->isEqual(elementType)) ||
8808-
packType->isEqual(packEnv->mapElementTypeIntoPackContext(elementType))) {
8807+
8808+
// Map element archetypes to the pack context to check for equality.
8809+
if (elementType->hasElementArchetype()) {
8810+
auto mappedPack = packEnv->mapElementTypeIntoPackContext(elementType);
8811+
return (packType->isEqual(mappedPack) ?
8812+
SolutionKind::Solved : SolutionKind::Error);
8813+
}
8814+
8815+
// Pack expansions can have concrete pattern types. In this case, the pack
8816+
// type and element type will be equal.
8817+
if (packType->isEqual(elementType)) {
88098818
return SolutionKind::Solved;
8810-
} else {
8811-
return SolutionKind::Error;
88128819
}
8820+
8821+
return SolutionKind::Error;
88138822
}
88148823

88158824
static bool isForKeyPathSubscript(ConstraintSystem &cs,

test/Constraints/pack-expansion-expressions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ func generateTuple<each T : Generatable>() -> (repeat each T) {
117117

118118
return (repeat (each T).generate())
119119
}
120+
121+
func packElementInvalidBinding<each T>(_ arg: repeat each T) {
122+
_ = (repeat print(each arg))
123+
}

0 commit comments

Comments
 (0)