[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

@@ -465,8 +465,8 @@ enum class FixKind : uint8_t {
/// Ignore an attempt to specialize a non-generic type.
AllowConcreteTypeSpecialization,
/// Ignore an attempt to specialize a generic function.
AllowGenericFunctionSpecialization,
/// Ignore an attempt to specialize a (generic) function reference.
AllowFunctionSpecialization,
/// Ignore an out-of-place \c then statement.
IgnoreOutOfPlaceThenStmt,
@@ -3750,17 +3750,19 @@ public:
}
};
class AllowGenericFunctionSpecialization final : public ConstraintFix {
class AllowFunctionSpecialization final : public ConstraintFix {
ValueDecl *Decl;
AllowGenericFunctionSpecialization(ConstraintSystem &cs, ValueDecl *decl,
ConstraintLocator *locator)
: ConstraintFix(cs, FixKind::AllowGenericFunctionSpecialization, locator),
AllowFunctionSpecialization(ConstraintSystem &cs, ValueDecl *decl,
ConstraintLocator *locator,
FixBehavior fixBehavior)
: ConstraintFix(cs, FixKind::AllowFunctionSpecialization, locator,
fixBehavior),
Decl(decl) {}
public:
std::string getName() const override {
return "allow generic function specialization";
return "allow (generic) function specialization";
}
bool diagnose(const Solution &solution, bool asNote = false) const override;
@@ -3769,11 +3771,11 @@ public:
return diagnose(*commonFixes.front().first);
}
static AllowGenericFunctionSpecialization *
static AllowFunctionSpecialization *
create(ConstraintSystem &cs, ValueDecl *decl, ConstraintLocator *locator);
static bool classof(const ConstraintFix *fix) {
return fix->getKind() == FixKind::AllowGenericFunctionSpecialization;
return fix->getKind() == FixKind::AllowFunctionSpecialization;
}
};