Skip to content

Commit

Permalink
Merge pull request swiftlang#26436 from xymus/fix-require-availability
Browse files Browse the repository at this point in the history
Fix -require-explicit-availability to handle unavailable decls correctly
  • Loading branch information
xymus authored Aug 23, 2019
2 parents bdf0890 + c84e9df commit 075dd74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,9 @@ void swift::checkExplicitAvailability(Decl *decl) {
// Warn on decls without an introduction version.
auto &ctx = decl->getASTContext();
auto safeRangeUnderApprox = AvailabilityInference::availableRange(decl, ctx);
if (!safeRangeUnderApprox.getOSVersion().hasLowerEndpoint()) {
if (!safeRangeUnderApprox.getOSVersion().hasLowerEndpoint() &&
!decl->getAttrs().isUnavailable(ctx)) {

auto diag = decl->diagnose(diag::public_decl_needs_availability);

auto suggestPlatform = decl->getASTContext().LangOpts.RequireExplicitAvailabilityTarget;
Expand Down
6 changes: 6 additions & 0 deletions test/attr/require_explicit_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ func bar() { } // expected-warning {{public declarations should have an availabi
@available(macOS 10.1, *)
public func ok() { }

@available(macOS, unavailable)
public func unavailableOk() { }

@available(macOS, deprecated: 10.10)
public func missingIntro() { } // expected-warning {{public declarations should have an availability attribute with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}}

@available(iOS 9.0, *)
public func missingTargetPlatform() { } // expected-warning {{public declarations should have an availability attribute with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}}

func privateFunc() { }

@_alwaysEmitIntoClient
Expand Down

0 comments on commit 075dd74

Please sign in to comment.