Skip to content

Commit 3714c48

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.
1 parent 756fe15 commit 3714c48

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
@@ -4282,16 +4282,17 @@ ConstraintSystem::matchTypesBindTypeVar(
42824282
// pack expansion expression.
42834283
if (!typeVar->getImpl().canBindToPack() &&
42844284
(type->is<PackArchetypeType>() || type->is<PackType>())) {
4285-
if (shouldAttemptFixes()) {
4286-
auto *fix = AllowInvalidPackReference::create(*this, type,
4287-
getConstraintLocator(locator));
4288-
if (!recordFix(fix)) {
4289-
recordPotentialHole(typeVar);
4290-
return getTypeMatchSuccess();
4291-
}
4292-
}
4285+
if (!shouldAttemptFixes())
4286+
return getTypeMatchFailure(locator);
42934287

4294-
return getTypeMatchFailure(locator);
4288+
auto *fix = AllowInvalidPackReference::create(
4289+
*this, type, getConstraintLocator(locator));
4290+
if (recordFix(fix))
4291+
return getTypeMatchFailure(locator);
4292+
4293+
// Don't allow the invalid pack reference to propagate to other
4294+
// bindings.
4295+
type = PlaceholderType::get(typeVar->getASTContext(), typeVar);
42954296
}
42964297

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

0 commit comments

Comments
 (0)