@@ -4261,6 +4261,13 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
42614261// / Should we warn that \p decl needs an explicit availability annotation
42624262// / in -require-explicit-availability mode?
42634263static bool declNeedsExplicitAvailability (const Decl *decl) {
4264+ auto &ctx = decl->getASTContext ();
4265+
4266+ // Don't require an introduced version on platforms that don't support
4267+ // versioned availability.
4268+ if (!ctx.supportsVersionedAvailability ())
4269+ return false ;
4270+
42644271 // Skip non-public decls.
42654272 if (auto valueDecl = dyn_cast<const ValueDecl>(decl)) {
42664273 AccessScope scope =
@@ -4281,17 +4288,16 @@ static bool declNeedsExplicitAvailability(const Decl *decl) {
42814288 return false ;
42824289
42834290 // Warn on decls without an introduction version.
4284- auto &ctx = decl->getASTContext ();
42854291 auto safeRangeUnderApprox = AvailabilityInference::availableRange (decl, ctx);
42864292 return !safeRangeUnderApprox.getOSVersion ().hasLowerEndpoint ();
42874293}
42884294
42894295void swift::checkExplicitAvailability (Decl *decl) {
42904296 // Skip if the command line option was not set and
42914297 // accessors as we check the pattern binding decl instead.
4292- auto DiagLevel = decl->getASTContext (). LangOpts . RequireExplicitAvailability ;
4293- if (! DiagLevel ||
4294- isa<AccessorDecl>(decl))
4298+ auto &ctx = decl->getASTContext ();
4299+ auto DiagLevel = ctx. LangOpts . RequireExplicitAvailability ;
4300+ if (!DiagLevel || isa<AccessorDecl>(decl))
42954301 return ;
42964302
42974303 // Only look at decls at module level or in extensions.
@@ -4336,8 +4342,7 @@ void swift::checkExplicitAvailability(Decl *decl) {
43364342 auto diag = decl->diagnose (diag::public_decl_needs_availability);
43374343 diag.limitBehavior (*DiagLevel);
43384344
4339- auto suggestPlatform =
4340- decl->getASTContext ().LangOpts .RequireExplicitAvailabilityTarget ;
4345+ auto suggestPlatform = ctx.LangOpts .RequireExplicitAvailabilityTarget ;
43414346 if (!suggestPlatform.empty ()) {
43424347 auto InsertLoc = decl->getAttrs ().getStartLoc (/* forModifiers=*/ false );
43434348 if (InsertLoc.isInvalid ())
@@ -4350,7 +4355,6 @@ void swift::checkExplicitAvailability(Decl *decl) {
43504355 {
43514356 llvm::raw_string_ostream Out (AttrText);
43524357
4353- auto &ctx = decl->getASTContext ();
43544358 StringRef OriginalIndent = Lexer::getIndentationForLine (
43554359 ctx.SourceMgr , InsertLoc);
43564360 Out << " @available(" << suggestPlatform << " , *)\n "
0 commit comments