[ConstraintSystem] Downgrade some invalid specialization uses to a warning until Swift 6 language mode

Some invalid specializations were previously allowed by the compiler
and we found some existing code that used that (albeit invalid) syntax,
so we need to stage that error as a warning until Swift 6 language mode
to avoid source compatibility break.

Resolves: rdar://134740240
This commit is contained in:
Pavel Yaskevich
2024-08-29 00:11:01 -07:00
parent 00eee36ea7
commit 2a6cc12a63
8 changed files with 85 additions and 42 deletions

View File

@@ -14069,6 +14069,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
auto genericParams = getGenericParams(decl);
if (!decl->getAsGenericContext() || !genericParams) {
if (isa<AbstractFunctionDecl>(decl)) {
return recordFix(AllowFunctionSpecialization::create(
*this, decl, getConstraintLocator(locator)))
? SolutionKind::Error
: SolutionKind::Solved;
}
// Allow concrete macros to have specializations with just a warning.
return recordFix(AllowConcreteTypeSpecialization::create(
*this, type1, decl, getConstraintLocator(locator),
@@ -14111,10 +14118,7 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
// FIXME: We could support explicit function specialization.
if (openedGenericParams.empty() ||
(isa<AbstractFunctionDecl>(decl) && !hasParameterPack)) {
if (!shouldAttemptFixes())
return SolutionKind::Error;
return recordFix(AllowGenericFunctionSpecialization::create(
return recordFix(AllowFunctionSpecialization::create(
*this, decl, getConstraintLocator(locator)))
? SolutionKind::Error
: SolutionKind::Solved;
@@ -15246,7 +15250,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
case FixKind::AllowAssociatedValueMismatch:
case FixKind::GenericArgumentsMismatch:
case FixKind::AllowConcreteTypeSpecialization:
case FixKind::AllowGenericFunctionSpecialization:
case FixKind::AllowFunctionSpecialization:
case FixKind::IgnoreGenericSpecializationArityMismatch:
case FixKind::IgnoreKeyPathSubscriptIndexMismatch:
case FixKind::AllowMemberRefOnExistential: {