3030
3131using namespace swift ;
3232
33- // / Returns true if there is any availability attribute on the declaration
34- // / that is active.
35- // FIXME: [availability] De-duplicate this with TypeCheckAvailability.cpp.
36- static bool hasActiveAvailableAttribute (const Decl *decl, ASTContext &ctx) {
37- decl = decl->getAbstractSyntaxDeclForAttributes ();
38-
39- for (auto attr : decl->getSemanticAvailableAttrs ()) {
40- if (attr.isActive (ctx))
41- return true ;
42- }
43-
44- return false ;
45- }
46-
4733static bool computeContainedByDeploymentTarget (AvailabilityScope *scope,
4834 ASTContext &ctx) {
4935 return scope->getPlatformAvailabilityRange ().isContainedIn (
@@ -397,7 +383,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
397383 return nullptr ;
398384
399385 // Declarations with explicit availability attributes always get a scope.
400- if (hasActiveAvailableAttribute ( decl, Context )) {
386+ if (decl-> hasAnyActiveAvailableAttr ( )) {
401387 return AvailabilityScope::createForDecl (
402388 Context, decl, getCurrentScope (),
403389 getEffectiveAvailabilityForDeclSignature (decl),
@@ -423,16 +409,20 @@ class AvailabilityScopeBuilder : private ASTWalker {
423409 getEffectiveAvailabilityForDeclSignature (const Decl *decl) {
424410 auto effectiveIntroduction = AvailabilityRange::alwaysAvailable ();
425411
426- // Availability attributes are found abstract syntax decls.
412+ // Availability attributes are found on abstract syntax decls.
427413 decl = decl->getAbstractSyntaxDeclForAttributes ();
428414
429415 // As a special case, extension decls are treated as effectively as
430416 // available as the nominal type they extend, up to the deployment target.
431417 // This rule is a convenience for library authors who have written
432- // extensions without specifying availabilty on the extension itself.
418+ // extensions without specifying platform availabilty on the extension
419+ // itself.
433420 if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
434421 auto extendedType = extension->getExtendedType ();
435- if (extendedType && !hasActiveAvailableAttribute (decl, Context)) {
422+ if (extendedType && !decl->hasAnyMatchingActiveAvailableAttr (
423+ [](SemanticAvailableAttr attr) -> bool {
424+ return attr.getDomain ().isPlatform ();
425+ })) {
436426 effectiveIntroduction.intersectWith (
437427 swift::AvailabilityInference::inferForType (extendedType));
438428
@@ -1087,9 +1077,9 @@ class AvailabilityScopeBuilder : private ASTWalker {
10871077 // current scope is completely contained in the range for the spec, then
10881078 // a version query can never be false, so the spec is useless.
10891079 // If so, report this.
1090- // FIXME: [availability] Diagnose non-platform queries as useless too.
1091- auto explicitRange = currentScope->getExplicitAvailabilityRange ();
1092- if (domain. isPlatform () && explicitRange && trueRange &&
1080+ auto explicitRange =
1081+ currentScope->getExplicitAvailabilityRange (domain, Context );
1082+ if (explicitRange && trueRange &&
10931083 explicitRange->isContainedIn (*trueRange)) {
10941084 // Platform unavailability queries never refine availability so don't
10951085 // diangose them.
@@ -1098,17 +1088,9 @@ class AvailabilityScopeBuilder : private ASTWalker {
10981088
10991089 DiagnosticEngine &diags = Context.Diags ;
11001090 if (currentScope->getReason () != AvailabilityScope::Reason::Root) {
1101- PlatformKind bestPlatform = targetPlatform (Context.LangOpts );
1102-
1103- // If possible, try to report the diagnostic in terms for the
1104- // platform the user uttered in the '#available()'. For a platform
1105- // that inherits availability from another platform it may be
1106- // different from the platform specified in the target triple.
1107- if (domain.getPlatformKind () != PlatformKind::none)
1108- bestPlatform = domain.getPlatformKind ();
11091091 diags.diagnose (query->getLoc (),
11101092 diag::availability_query_useless_enclosing_scope,
1111- platformString (bestPlatform ));
1093+ domain. getNameForAttributePrinting ( ));
11121094 diags.diagnose (
11131095 currentScope->getIntroductionLoc (),
11141096 diag::availability_query_useless_enclosing_scope_here);
0 commit comments