Merge pull request #64498 from hborla/diagnose-pack-outside-expansion-expr

[ConstraintSystem] Enforce `TVO_CanBindToPack`, and diagnose pack references outside of pack expansion expressions.
This commit is contained in:
Holly Borla
2023-03-21 14:00:52 -07:00
committed by GitHub
9 changed files with 124 additions and 9 deletions

View File

@@ -4294,6 +4294,23 @@ ConstraintSystem::matchTypesBindTypeVar(
}
}
// If we're attempting to bind a PackType or PackArchetypeType to a type
// variable that doesn't support it, we have a pack reference outside of a
// 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();
}
}
return getTypeMatchFailure(locator);
}
// We do not allow keypaths to go through AnyObject. Let's create a fix
// so this can be diagnosed later.
if (auto loc = typeVar->getImpl().getLocator()) {
@@ -14153,6 +14170,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::RenameConflictingPatternVariables:
case FixKind::MustBeCopyable:
case FixKind::AllowInvalidPackElement:
case FixKind::AllowInvalidPackReference:
case FixKind::MacroMissingPound:
case FixKind::AllowGlobalActorMismatch:
case FixKind::GenericArgumentsMismatch: {