@@ -13858,6 +13858,23 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1385813858 return genericParams;
1385913859 };
1386013860
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+
1386113878 ValueDecl *decl;
1386213879 SmallVector<OpenedType, 2> openedTypes;
1386313880 if (auto *bound = dyn_cast<TypeAliasType>(type1.getPointer())) {
@@ -13916,6 +13933,12 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1391613933 decl = overloadChoice.getDecl();
1391713934
1391813935 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+ }
1391913942
1392013943 auto genericParams = getGenericParams(decl);
1392113944 if (genericParams) {
@@ -13931,22 +13954,8 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1393113954 }
1393213955
1393313956 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);
1395013959
1395113960 // Map the generic parameters we have over to their opened types.
1395213961 bool hasParameterPack = false;
0 commit comments