Skip to content

Commit 16ac355

Browse files
committed
Sema: Fix required availability diagnostics for protocol extensions.
Extending a protocol cannot introduce new conformances to other protocols, so skip checking for associated conformances to public protocols when diagnosing required availability on such an extension. Resolves rdar://133873836.
1 parent 4921eaf commit 16ac355

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ bool swift::isExported(const ValueDecl *VD) {
8686
}
8787

8888
static bool hasConformancesToPublicProtocols(const ExtensionDecl *ED) {
89+
auto nominal = ED->getExtendedNominal();
90+
if (!nominal)
91+
return false;
92+
93+
// Extensions of protocols cannot introduce additional conformances.
94+
if (isa<ProtocolDecl>(nominal))
95+
return false;
96+
8997
auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
9098
for (const ProtocolDecl *PD : protocols) {
9199
AccessScope scope =

test/attr/require_explicit_availability_macos.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,23 @@ extension StructWithImplicitMembers: Hashable { }
237237
// expected-note @-1 {{add @available attribute to enclosing extension}}
238238
// expected-warning @-2 {{public declarations should have an availability attribute with an introduction version}}
239239
// expected-error @-3 {{'StructWithImplicitMembers' is only available in macOS 10.15 or newer}}
240+
241+
extension PublicProtocol {}
242+
243+
extension PublicProtocol {
244+
internal var internalVar: Bool { return true }
245+
}
246+
247+
extension PublicProtocol { // expected-warning {{public declarations should have an availability attribute with an introduction version}}
248+
public var publicVar: Bool { return true } // expected-warning {{public declarations should have an availability attribute with an introduction version}}
249+
}
250+
251+
extension Error {}
252+
253+
extension Error {
254+
internal var internalVar: Bool { return true }
255+
}
256+
257+
extension Error { // expected-warning {{public declarations should have an availability attribute with an introduction version}}
258+
public var publicVar: Bool { return true } // expected-warning {{public declarations should have an availability attribute with an introduction version}}
259+
}

0 commit comments

Comments
 (0)