Skip to content

Commit 0c5fd6a

Browse files
authored
Merge pull request swiftlang#80481 from tshortli/require-explicit-availability-extension-with-spi
Sema: Fix a regression in `-require-explicit-availability` diagnostics
2 parents 4d28cc6 + 5cd5f31 commit 0c5fd6a

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

include/swift/AST/DeclExportabilityVisitor.h

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ bool isExported(const ValueDecl *VD);
190190
/// A specialization of `isExported` for `ExtensionDecl`.
191191
bool isExported(const ExtensionDecl *ED);
192192

193+
/// Returns true if the extension declares any protocol conformances that
194+
/// require the extension to be exported.
195+
bool hasConformancesToPublicProtocols(const ExtensionDecl *ED);
196+
193197
} // end namespace swift
194198

195199
#endif

lib/AST/Availability.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ bool swift::isExported(const ValueDecl *VD) {
11441144
return false;
11451145
}
11461146

1147-
static bool hasConformancesToPublicProtocols(const ExtensionDecl *ED) {
1147+
bool swift::hasConformancesToPublicProtocols(const ExtensionDecl *ED) {
11481148
auto nominal = ED->getExtendedNominal();
11491149
if (!nominal)
11501150
return false;

lib/Sema/TypeCheckAvailability.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,7 @@ void swift::checkExplicitAvailability(Decl *decl) {
35213521
return false;
35223522
});
35233523

3524-
if (!hasMembers && !isExported(extension))
3524+
if (!hasMembers && !hasConformancesToPublicProtocols(extension))
35253525
return;
35263526
} else if (auto pbd = dyn_cast<PatternBindingDecl>(decl)) {
35273527
// Check the first var instead.

test/attr/require_explicit_availability_macos.swift

+26-12
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
// RUN: %empty-directory(%t)
44

55
/// Using the flag directly raises warnings and fixits.
6-
// RUN: %swiftc_driver -typecheck -parse-as-library -Xfrontend -verify %s \
7-
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability \
8-
// RUN: -require-explicit-availability-target "macOS 10.10"
9-
// RUN: %swiftc_driver -typecheck -parse-as-library -Xfrontend -verify %s \
10-
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=warn \
11-
// RUN: -require-explicit-availability-target "macOS 10.10"
6+
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s \
7+
// RUN: -target %target-cpu-apple-macosx10.10 -package-name Foo \
8+
// RUN: -require-explicit-availability -require-explicit-availability-target "macOS 10.10"
9+
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s \
10+
// RUN: -target %target-cpu-apple-macosx10.10 -package-name Foo \
11+
// RUN: -require-explicit-availability=warn -require-explicit-availability-target "macOS 10.10"
1212

1313
/// Using -library-level api defaults to enabling warnings, without fixits.
1414
// RUN: sed -e "s/}} {{.*/}}/" < %s > %t/NoFixits.swift
1515
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/NoFixits.swift \
16-
// RUN: -target %target-cpu-apple-macosx10.10 -library-level api
16+
// RUN: -target %target-cpu-apple-macosx10.10 -package-name Foo -library-level api
1717

1818
/// Explicitly disable the diagnostic.
1919
// RUN: sed -e 's/xpected-warning/not-something-expected/' < %s > %t/None.swift
2020
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/None.swift \
21-
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=ignore \
22-
// RUN: -require-explicit-availability-target "macOS 10.10" -library-level api
21+
// RUN: -target %target-cpu-apple-macosx10.10 -package-name Foo -library-level api \
22+
// RUN: -require-explicit-availability=ignore -require-explicit-availability-target "macOS 10.10"
2323

2424
/// Upgrade the diagnostic to an error.
2525
// RUN: sed -e "s/xpected-warning/xpected-error/" < %s > %t/Errors.swift
2626
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/Errors.swift \
27-
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=error \
28-
// RUN: -require-explicit-availability-target "macOS 10.10"
27+
// RUN: -target %target-cpu-apple-macosx10.10 -package-name Foo \
28+
// RUN: -require-explicit-availability=error -require-explicit-availability-target "macOS 10.10"
2929

3030
/// Error on an invalid argument.
3131
// RUN: not %target-swift-frontend -typecheck %s -require-explicit-availability=NotIt 2>&1 \
@@ -58,7 +58,9 @@ public func missingIntro() { } // expected-warning {{public declarations should
5858
@available(iOS 9.0, *)
5959
public func missingTargetPlatform() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{-1:1-1=@available(macOS 10.10, *)\n}}
6060

61-
func privateFunc() { }
61+
private func privateFunc() { }
62+
internal func internalFunc() { }
63+
package func packageFunc() { }
6264

6365
@_alwaysEmitIntoClient
6466
public func alwaysEmitted() { }
@@ -113,6 +115,18 @@ extension S {
113115
extension S {
114116
internal func dontWarnWithoutPublicMembers() { }
115117
private func dontWarnWithoutPublicMembers1() { }
118+
package func dontWarnWithoutPublicMembers2() { }
119+
}
120+
121+
extension S {
122+
@_spi(SPIsAreOK)
123+
public func dontWarnWithSPIMembers() {}
124+
125+
@available(macOS, unavailable)
126+
public func dontWarnWithUnavailableMembers() { }
127+
128+
@_alwaysEmitIntoClient
129+
public func dontWarnWithAEICMembers() { }
116130
}
117131

118132
// An empty extension should be ok.

0 commit comments

Comments
 (0)