@@ -13868,6 +13868,23 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1386813868 return genericParams;
1386913869 };
1387013870
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+
1387113888 ValueDecl *decl;
1387213889 SmallVector<OpenedType, 2> openedTypes;
1387313890 if (auto *bound = dyn_cast<TypeAliasType>(type1.getPointer())) {
@@ -13926,6 +13943,12 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1392613943 decl = overloadChoice.getDecl();
1392713944
1392813945 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+ }
1392913952
1393013953 auto genericParams = getGenericParams(decl);
1393113954 if (genericParams) {
@@ -13941,22 +13964,8 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1394113964 }
1394213965
1394313966 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);
1396013969
1396113970 // Map the generic parameters we have over to their opened types.
1396213971 bool hasParameterPack = false;
0 commit comments