Skip to content

Sema: Fix required availability diagnostics for protocol extensions #76071

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
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
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ bool swift::isExported(const ValueDecl *VD) {
}

static bool hasConformancesToPublicProtocols(const ExtensionDecl *ED) {
auto nominal = ED->getExtendedNominal();
if (!nominal)
return false;

// Extensions of protocols cannot introduce additional conformances.
if (isa<ProtocolDecl>(nominal))
return false;

auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
for (const ProtocolDecl *PD : protocols) {
AccessScope scope =
Expand Down
20 changes: 20 additions & 0 deletions test/attr/require_explicit_availability_macos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,23 @@ extension StructWithImplicitMembers: Hashable { }
// expected-note @-1 {{add @available attribute to enclosing extension}}
// expected-warning @-2 {{public declarations should have an availability attribute with an introduction version}}
// expected-error @-3 {{'StructWithImplicitMembers' is only available in macOS 10.15 or newer}}

extension PublicProtocol {}

extension PublicProtocol {
internal var internalVar: Bool { return true }
}

extension PublicProtocol { // expected-warning {{public declarations should have an availability attribute with an introduction version}}
public var publicVar: Bool { return true } // expected-warning {{public declarations should have an availability attribute with an introduction version}}
}

extension Error {}

extension Error {
internal var internalVar: Bool { return true }
}

extension Error { // expected-warning {{public declarations should have an availability attribute with an introduction version}}
public var publicVar: Bool { return true } // expected-warning {{public declarations should have an availability attribute with an introduction version}}
}