@@ -13868,6 +13868,23 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13868
13868
return genericParams;
13869
13869
};
13870
13870
13871
+ auto fixInvalidSpecialization = [&](ValueDecl *decl) -> SolutionKind {
13872
+ if (isa<AbstractFunctionDecl>(decl)) {
13873
+ return recordFix(AllowFunctionSpecialization::create(
13874
+ *this, decl, getConstraintLocator(locator)))
13875
+ ? SolutionKind::Error
13876
+ : SolutionKind::Solved;
13877
+ }
13878
+
13879
+ // Allow concrete macros to have specializations with just a warning.
13880
+ return recordFix(AllowConcreteTypeSpecialization::create(
13881
+ *this, type1, decl, getConstraintLocator(locator),
13882
+ isa<MacroDecl>(decl) ? FixBehavior::DowngradeToWarning
13883
+ : FixBehavior::Error))
13884
+ ? SolutionKind::Error
13885
+ : SolutionKind::Solved;
13886
+ };
13887
+
13871
13888
ValueDecl *decl;
13872
13889
SmallVector<OpenedType, 2> openedTypes;
13873
13890
if (auto *bound = dyn_cast<TypeAliasType>(type1.getPointer())) {
@@ -13926,6 +13943,12 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13926
13943
decl = overloadChoice.getDecl();
13927
13944
13928
13945
auto openedOverloadTypes = getOpenedTypes(overloadLocator);
13946
+ // Attempting to specialize a non-generic declaration.
13947
+ if (openedOverloadTypes.empty()) {
13948
+ // Note that this is unconditional because the fix is
13949
+ // downgraded to a warning in swift language modes < 6.
13950
+ return fixInvalidSpecialization(decl);
13951
+ }
13929
13952
13930
13953
auto genericParams = getGenericParams(decl);
13931
13954
if (genericParams) {
@@ -13941,22 +13964,8 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13941
13964
}
13942
13965
13943
13966
auto genericParams = getGenericParams(decl);
13944
- if (!decl->getAsGenericContext() || !genericParams) {
13945
- if (isa<AbstractFunctionDecl>(decl)) {
13946
- return recordFix(AllowFunctionSpecialization::create(
13947
- *this, decl, getConstraintLocator(locator)))
13948
- ? SolutionKind::Error
13949
- : SolutionKind::Solved;
13950
- }
13951
-
13952
- // Allow concrete macros to have specializations with just a warning.
13953
- return recordFix(AllowConcreteTypeSpecialization::create(
13954
- *this, type1, decl, getConstraintLocator(locator),
13955
- isa<MacroDecl>(decl) ? FixBehavior::DowngradeToWarning
13956
- : FixBehavior::Error))
13957
- ? SolutionKind::Error
13958
- : SolutionKind::Solved;
13959
- }
13967
+ if (!decl->getAsGenericContext() || !genericParams)
13968
+ return fixInvalidSpecialization(decl);
13960
13969
13961
13970
// Map the generic parameters we have over to their opened types.
13962
13971
bool hasParameterPack = false;
0 commit comments