@@ -4260,6 +4260,13 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
42604260// / Should we warn that \p decl needs an explicit availability annotation
42614261// / in -require-explicit-availability mode?
42624262static bool declNeedsExplicitAvailability (const Decl *decl) {
4263+ auto &ctx = decl->getASTContext ();
4264+
4265+ // Don't require an introduced version on platforms that don't support
4266+ // versioned availability.
4267+ if (!ctx.supportsVersionedAvailability ())
4268+ return false ;
4269+
42634270 // Skip non-public decls.
42644271 if (auto valueDecl = dyn_cast<const ValueDecl>(decl)) {
42654272 AccessScope scope =
@@ -4280,17 +4287,16 @@ static bool declNeedsExplicitAvailability(const Decl *decl) {
42804287 return false ;
42814288
42824289 // Warn on decls without an introduction version.
4283- auto &ctx = decl->getASTContext ();
42844290 auto safeRangeUnderApprox = AvailabilityInference::availableRange (decl, ctx);
42854291 return !safeRangeUnderApprox.getOSVersion ().hasLowerEndpoint ();
42864292}
42874293
42884294void swift::checkExplicitAvailability (Decl *decl) {
42894295 // Skip if the command line option was not set and
42904296 // accessors as we check the pattern binding decl instead.
4291- auto DiagLevel = decl->getASTContext (). LangOpts . RequireExplicitAvailability ;
4292- if (! DiagLevel ||
4293- isa<AccessorDecl>(decl))
4297+ auto &ctx = decl->getASTContext ();
4298+ auto DiagLevel = ctx. LangOpts . RequireExplicitAvailability ;
4299+ if (!DiagLevel || isa<AccessorDecl>(decl))
42944300 return ;
42954301
42964302 // Only look at decls at module level or in extensions.
@@ -4335,8 +4341,7 @@ void swift::checkExplicitAvailability(Decl *decl) {
43354341 auto diag = decl->diagnose (diag::public_decl_needs_availability);
43364342 diag.limitBehavior (*DiagLevel);
43374343
4338- auto suggestPlatform =
4339- decl->getASTContext ().LangOpts .RequireExplicitAvailabilityTarget ;
4344+ auto suggestPlatform = ctx.LangOpts .RequireExplicitAvailabilityTarget ;
43404345 if (!suggestPlatform.empty ()) {
43414346 auto InsertLoc = decl->getAttrs ().getStartLoc (/* forModifiers=*/ false );
43424347 if (InsertLoc.isInvalid ())
@@ -4349,7 +4354,6 @@ void swift::checkExplicitAvailability(Decl *decl) {
43494354 {
43504355 llvm::raw_string_ostream Out (AttrText);
43514356
4352- auto &ctx = decl->getASTContext ();
43534357 StringRef OriginalIndent = Lexer::getIndentationForLine (
43544358 ctx.SourceMgr , InsertLoc);
43554359 Out << " @available(" << suggestPlatform << " , *)\n "
0 commit comments