Skip to content

Sema: Fix another -require-explicit-availability regression #80613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3511,6 +3511,11 @@ void swift::checkExplicitAvailability(Decl *decl) {
!isa<ExtensionDecl>(decl->getDeclContext())) return;

if (auto extension = dyn_cast<ExtensionDecl>(decl)) {
// Skip extensions that extend non-public types.
auto extended = extension->getExtendedNominal();
if (!extended || !extended->getFormalAccessScope().isPublic())
return;

// Skip extensions when none of their members need availability.
auto members = extension->getMembers();
auto hasMembers = std::any_of(members.begin(), members.end(),
Expand Down
4 changes: 4 additions & 0 deletions test/attr/require_explicit_availability_macos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ private class PrivateClass { }

extension PrivateClass { }

extension PrivateClass : P { }

@available(macOS 10.1, *)
public protocol PublicProtocol { }

Expand All @@ -162,6 +164,8 @@ extension spiStruct {
public func spiExtensionMethod() {}
}

extension spiStruct : P { }

public var publicVar = S() // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}}

@available(macOS 10.10, *)
Expand Down