@@ -2417,27 +2417,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *parsedAttr) {
24172417 }
24182418 }
24192419
2420- SourceLoc attrLoc = parsedAttr->getLocation ();
2421- auto versionAvailability = attr->getVersionAvailability (Ctx);
2422- if (versionAvailability == AvailableVersionComparison::Obsoleted ||
2423- versionAvailability == AvailableVersionComparison::Unavailable) {
2424- if (auto cannotBeUnavailable =
2425- TypeChecker::diagnosticIfDeclCannotBeUnavailable (D)) {
2426- diagnose (attrLoc, cannotBeUnavailable.value ());
2427- return ;
2428- }
2429-
2430- if (auto *PD = dyn_cast<ProtocolDecl>(DC)) {
2431- if (auto *VD = dyn_cast<ValueDecl>(D)) {
2432- if (VD->isProtocolRequirement () && !PD->isObjC ()) {
2433- diagnoseAndRemoveAttr (parsedAttr,
2434- diag::unavailable_method_non_objc_protocol);
2435- return ;
2436- }
2437- }
2438- }
2439- }
2440-
24412420 // The remaining diagnostics are only for attributes with introduced versions
24422421 // for specific platforms.
24432422 if (!attr->isPlatformSpecific () || !attr->getIntroduced ().has_value ())
@@ -2486,18 +2465,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *parsedAttr) {
24862465 }
24872466 }
24882467 }
2489-
2490- std::optional<Diagnostic> MaybeNotAllowed =
2491- TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable (D);
2492- if (MaybeNotAllowed.has_value ()) {
2493- AvailabilityRange DeploymentRange =
2494- AvailabilityRange::forDeploymentTarget (Ctx);
2495- if (EnclosingAnnotatedRange.has_value ())
2496- DeploymentRange.intersectWith (*EnclosingAnnotatedRange);
2497-
2498- if (!DeploymentRange.isContainedIn (AttrRange))
2499- diagnose (attrLoc, MaybeNotAllowed.value ());
2500- }
25012468}
25022469
25032470static bool canDeclareSymbolName (StringRef symbol, ModuleDecl *fromModule) {
@@ -5003,6 +4970,54 @@ void AttributeChecker::checkAvailableAttrs(ArrayRef<AvailableAttr *> Attrs) {
50034970 diagnose (D->getLoc (), diag::spi_preferred_over_spi_available);
50044971 }
50054972 }
4973+
4974+ if (Ctx.LangOpts .DisableAvailabilityChecking )
4975+ return ;
4976+
4977+ // Compute availability constraints for the decl, relative to its parent
4978+ // declaration or to the deployment target.
4979+ auto availabilityContext = AvailabilityContext::forDeploymentTarget (Ctx);
4980+ if (auto parent =
4981+ AvailabilityInference::parentDeclForInferredAvailability (D)) {
4982+ auto parentAvailability = TypeChecker::availabilityForDeclSignature (parent);
4983+ availabilityContext.constrainWithContext (parentAvailability, Ctx);
4984+ }
4985+
4986+ auto availabilityConstraint =
4987+ getAvailabilityConstraintsForDecl (D, availabilityContext)
4988+ .getPrimaryConstraint ();
4989+ if (!availabilityConstraint)
4990+ return ;
4991+
4992+ // If the decl is unavailable relative to its parent and it's not a
4993+ // declaration that is allowed to be unavailable, diagnose.
4994+ if (availabilityConstraint->isUnavailable ()) {
4995+ auto attr = availabilityConstraint->getAttr ();
4996+ if (auto diag = TypeChecker::diagnosticIfDeclCannotBeUnavailable (D)) {
4997+ diagnose (attr.getParsedAttr ()->getLocation (), diag.value ());
4998+ return ;
4999+ }
5000+
5001+ if (auto *PD = dyn_cast<ProtocolDecl>(D->getDeclContext ())) {
5002+ if (auto *VD = dyn_cast<ValueDecl>(D)) {
5003+ if (VD->isProtocolRequirement () && !PD->isObjC ()) {
5004+ diagnoseAndRemoveAttr (
5005+ const_cast <AvailableAttr *>(attr.getParsedAttr ()),
5006+ diag::unavailable_method_non_objc_protocol);
5007+ return ;
5008+ }
5009+ }
5010+ }
5011+ }
5012+
5013+ // If the decl is potentially unavailable relative to its parent and it's
5014+ // not a declaration that is allowed to be potentially unavailable, diagnose.
5015+ if (availabilityConstraint->isPotentiallyAvailable ()) {
5016+ auto attr = availabilityConstraint->getAttr ();
5017+ if (auto diag =
5018+ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable (D))
5019+ diagnose (attr.getParsedAttr ()->getLocation (), diag.value ());
5020+ }
50065021}
50075022
50085023void AttributeChecker::checkBackDeployedAttrs (
0 commit comments