Skip to content

Commit 2852c59

Browse files
authored
Merge pull request swiftlang#79428 from tshortli/accept-unavailable-stored-properties-in-swiftinterfaces
Sema: Allow unavailable stored properties in swiftinterfaces
2 parents c2e36de + 9c15342 commit 2852c59

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5386,6 +5386,10 @@ TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
53865386
if (parentIsUnavailable(D))
53875387
return std::nullopt;
53885388

5389+
// Be lenient in interfaces to accomodate @_spi_available.
5390+
if (D->getDeclContext()->isInSwiftinterface())
5391+
return std::nullopt;
5392+
53895393
// Do not permit unavailable script-mode global variables; their initializer
53905394
// expression is not lazily evaluated, so this would not be safe.
53915395
if (VD->isTopLevelGlobal())
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-emit-module-interface(%t/Test.swiftinterface) %s -module-name Test -target %target-cpu-apple-macos51
4+
// RUN: %target-swift-typecheck-module-from-interface(%t/Test.swiftinterface) -module-name Test
5+
// RUN: %FileCheck %s < %t/Test.swiftinterface
6+
7+
// RUN: %target-swift-emit-module-interface(%t/TestMinInlining.swiftinterface) %s -module-name Test -target %target-cpu-apple-macos51 -target-min-inlining-version min
8+
// RUN: %target-swift-typecheck-module-from-interface(%t/TestMinInlining.swiftinterface) -module-name Test
9+
// RUN: %FileCheck %s < %t/TestMinInlining.swiftinterface
10+
11+
// REQUIRES: OS=macosx
12+
13+
// CHECK-LABEL: public struct StructWithProperties
14+
public struct StructWithProperties {
15+
// CHECK: @available(macOS, unavailable)
16+
// CHECK-NEXT: public var unavailableComputed: Swift.Int {
17+
// CHECK-NEXT: get
18+
// CHECK-NEXT: }
19+
@available(macOS, unavailable)
20+
public var unavailableComputed: Int { 1 }
21+
22+
// CHECK: @available(macOS 51, *)
23+
// CHECK-NEXT: public let introducedAtDeploymentStored: Swift.Int
24+
@available(macOS 51, *)
25+
public let introducedAtDeploymentStored: Int = 1
26+
27+
// CHECK: @available(macOS 99, *)
28+
// CHECK-NEXT: public var introducedAfterDeploymentComputed: Swift.Int {
29+
// CHECK-NEXT: get
30+
// CHECK-NEXT: }
31+
@available(macOS 99, *)
32+
public var introducedAfterDeploymentComputed: Int { 1 }
33+
34+
// CHECK: @available(macOS, unavailable)
35+
// CHECK-NEXT: public let introducedAtDeploymentSPIStored: Swift.Int
36+
@_spi_available(macOS 51, *)
37+
public let introducedAtDeploymentSPIStored: Int = 1
38+
}
39+
40+
// CHECK-LABEL: public enum EnumWithAssociatedValues
41+
public enum EnumWithAssociatedValues {
42+
// CHECK: @available(macOS, unavailable)
43+
// CHECK-NEXT: case unavailable
44+
@available(macOS, unavailable)
45+
case unavailable
46+
47+
// CHECK: @available(macOS 51, *)
48+
// CHECK-NEXT: case introducedAtDeployment
49+
@available(macOS 51, *)
50+
case introducedAtDeployment
51+
52+
// CHECK: @available(macOS 99, *)
53+
// CHECK-NEXT: case introducedAfterDeployment
54+
@available(macOS 99, *)
55+
case introducedAfterDeployment
56+
57+
// CHECK: @available(macOS, unavailable)
58+
// CHECK-NEXT: case unavailableWithAssoc(Swift.Int)
59+
@available(macOS, unavailable)
60+
case unavailableWithAssoc(Int)
61+
62+
// CHECK: @available(macOS 51, *)
63+
// CHECK-NEXT: case introducedAtDeploymentWithAssoc(Swift.Int)
64+
@available(macOS 51, *)
65+
case introducedAtDeploymentWithAssoc(Int)
66+
}

0 commit comments

Comments
 (0)