@@ -13858,6 +13858,23 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13858
13858
return genericParams;
13859
13859
};
13860
13860
13861
+ auto fixInvalidSpecialization = [&](ValueDecl *decl) -> SolutionKind {
13862
+ if (isa<AbstractFunctionDecl>(decl)) {
13863
+ return recordFix(AllowFunctionSpecialization::create(
13864
+ *this, decl, getConstraintLocator(locator)))
13865
+ ? SolutionKind::Error
13866
+ : SolutionKind::Solved;
13867
+ }
13868
+
13869
+ // Allow concrete macros to have specializations with just a warning.
13870
+ return recordFix(AllowConcreteTypeSpecialization::create(
13871
+ *this, type1, decl, getConstraintLocator(locator),
13872
+ isa<MacroDecl>(decl) ? FixBehavior::DowngradeToWarning
13873
+ : FixBehavior::Error))
13874
+ ? SolutionKind::Error
13875
+ : SolutionKind::Solved;
13876
+ };
13877
+
13861
13878
ValueDecl *decl;
13862
13879
SmallVector<OpenedType, 2> openedTypes;
13863
13880
if (auto *bound = dyn_cast<TypeAliasType>(type1.getPointer())) {
@@ -13916,6 +13933,12 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13916
13933
decl = overloadChoice.getDecl();
13917
13934
13918
13935
auto openedOverloadTypes = getOpenedTypes(overloadLocator);
13936
+ // Attempting to specialize a non-generic declaration.
13937
+ if (openedOverloadTypes.empty()) {
13938
+ // Note that this is unconditional because the fix is
13939
+ // downgraded to a warning in swift language modes < 6.
13940
+ return fixInvalidSpecialization(decl);
13941
+ }
13919
13942
13920
13943
auto genericParams = getGenericParams(decl);
13921
13944
if (genericParams) {
@@ -13931,22 +13954,8 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
13931
13954
}
13932
13955
13933
13956
auto genericParams = getGenericParams(decl);
13934
- if (!decl->getAsGenericContext() || !genericParams) {
13935
- if (isa<AbstractFunctionDecl>(decl)) {
13936
- return recordFix(AllowFunctionSpecialization::create(
13937
- *this, decl, getConstraintLocator(locator)))
13938
- ? SolutionKind::Error
13939
- : SolutionKind::Solved;
13940
- }
13941
-
13942
- // Allow concrete macros to have specializations with just a warning.
13943
- return recordFix(AllowConcreteTypeSpecialization::create(
13944
- *this, type1, decl, getConstraintLocator(locator),
13945
- isa<MacroDecl>(decl) ? FixBehavior::DowngradeToWarning
13946
- : FixBehavior::Error))
13947
- ? SolutionKind::Error
13948
- : SolutionKind::Solved;
13949
- }
13957
+ if (!decl->getAsGenericContext() || !genericParams)
13958
+ return fixInvalidSpecialization(decl);
13950
13959
13951
13960
// Map the generic parameters we have over to their opened types.
13952
13961
bool hasParameterPack = false;
0 commit comments