Skip to content

[CSSimplify] Prevent invalid pack references from causing infinite loops #64907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4282,16 +4282,17 @@ ConstraintSystem::matchTypesBindTypeVar(
// pack expansion expression.
if (!typeVar->getImpl().canBindToPack() &&
(type->is<PackArchetypeType>() || type->is<PackType>())) {
if (shouldAttemptFixes()) {
auto *fix = AllowInvalidPackReference::create(*this, type,
getConstraintLocator(locator));
if (!recordFix(fix)) {
recordPotentialHole(typeVar);
return getTypeMatchSuccess();
}
}
if (!shouldAttemptFixes())
return getTypeMatchFailure(locator);

return getTypeMatchFailure(locator);
auto *fix = AllowInvalidPackReference::create(
*this, type, getConstraintLocator(locator));
if (recordFix(fix))
return getTypeMatchFailure(locator);

// Don't allow the invalid pack reference to propagate to other
// bindings.
type = PlaceholderType::get(typeVar->getASTContext(), typeVar);
}

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