Skip to content

Commit 554f2a4

Browse files
committed
[CSSimplify] Prevent invalid pack references from causing infinite loops
When `matchTypesBindTypeVar` detects invalid pack reference it should reset the type to a placeholder and allow binding to go through, otherwise, if binding comes from inference, returning without binding would create an infinite loop because type variable would perpetually be the best choice to attempt. (cherry picked from commit 3714c48)
1 parent 47ac416 commit 554f2a4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,16 +4318,17 @@ ConstraintSystem::matchTypesBindTypeVar(
43184318
// pack expansion expression.
43194319
if (!typeVar->getImpl().canBindToPack() &&
43204320
(type->is<PackArchetypeType>() || type->is<PackType>())) {
4321-
if (shouldAttemptFixes()) {
4322-
auto *fix = AllowInvalidPackReference::create(*this, type,
4323-
getConstraintLocator(locator));
4324-
if (!recordFix(fix)) {
4325-
recordPotentialHole(typeVar);
4326-
return getTypeMatchSuccess();
4327-
}
4328-
}
4321+
if (!shouldAttemptFixes())
4322+
return getTypeMatchFailure(locator);
43294323

4330-
return getTypeMatchFailure(locator);
4324+
auto *fix = AllowInvalidPackReference::create(
4325+
*this, type, getConstraintLocator(locator));
4326+
if (recordFix(fix))
4327+
return getTypeMatchFailure(locator);
4328+
4329+
// Don't allow the invalid pack reference to propagate to other
4330+
// bindings.
4331+
type = PlaceholderType::get(typeVar->getASTContext(), typeVar);
43314332
}
43324333

43334334
// Binding to a pack expansion type is always an error in Swift 6 mode.

0 commit comments

Comments
 (0)