@@ -2417,27 +2417,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *parsedAttr) {
2417
2417
}
2418
2418
}
2419
2419
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
-
2441
2420
// The remaining diagnostics are only for attributes with introduced versions
2442
2421
// for specific platforms.
2443
2422
if (!attr->isPlatformSpecific () || !attr->getIntroduced ().has_value ())
@@ -2486,18 +2465,6 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *parsedAttr) {
2486
2465
}
2487
2466
}
2488
2467
}
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
- }
2501
2468
}
2502
2469
2503
2470
static bool canDeclareSymbolName (StringRef symbol, ModuleDecl *fromModule) {
@@ -5003,6 +4970,54 @@ void AttributeChecker::checkAvailableAttrs(ArrayRef<AvailableAttr *> Attrs) {
5003
4970
diagnose (D->getLoc (), diag::spi_preferred_over_spi_available);
5004
4971
}
5005
4972
}
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
+ }
5006
5021
}
5007
5022
5008
5023
void AttributeChecker::checkBackDeployedAttrs (
0 commit comments