File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -4932,6 +4932,12 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
4932
4932
if (auto *DD = dyn_cast<DestructorDecl>(D))
4933
4933
return Diagnostic (diag::availability_decl_no_potential, D);
4934
4934
4935
+ // Observing accessors are always called implicitly.
4936
+ if (auto *AD = dyn_cast<AccessorDecl>(D)) {
4937
+ if (AD->isObservingAccessor ())
4938
+ return Diagnostic (diag::availability_decl_no_potential, D);
4939
+ }
4940
+
4935
4941
if (auto *VD = dyn_cast<VarDecl>(D)) {
4936
4942
if (!VD->hasStorageOrWrapsStorage ())
4937
4943
return std::nullopt;
@@ -4987,6 +4993,12 @@ TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
4987
4993
if (auto *AT = dyn_cast<AssociatedTypeDecl>(D))
4988
4994
return Diagnostic (diag::availability_decl_no_unavailable, D);
4989
4995
4996
+ // Observing accessors are always called implicitly.
4997
+ if (auto *AD = dyn_cast<AccessorDecl>(D)) {
4998
+ if (AD->isObservingAccessor ())
4999
+ return Diagnostic (diag::availability_decl_no_unavailable, D);
5000
+ }
5001
+
4990
5002
if (auto *VD = dyn_cast<VarDecl>(D)) {
4991
5003
if (!VD->hasStorageOrWrapsStorage ())
4992
5004
return std::nullopt;
Original file line number Diff line number Diff line change @@ -98,7 +98,6 @@ struct SubscriptHelper {
98
98
@available ( * , unavailable)
99
99
set { } // expected-note {{setter for 'subscript(unavailableGetterAndSetter:)' has been explicitly marked unavailable here}}
100
100
}
101
-
102
101
}
103
102
104
103
@discardableResult func takesInOut< T> ( _ t: inout T ) -> T {
@@ -553,3 +552,22 @@ struct TestPatternBindingInitExprs {
553
552
var unavailableGetterAndSetter_0 = global. unavailableGetterAndSetter [ 0 ] // expected-error {{getter for 'unavailableGetterAndSetter' is unavailable}}
554
553
var unavailableGetterAndSetter_0_b = global. unavailableGetterAndSetter [ 0 ] . b // expected-error {{getter for 'unavailableGetterAndSetter' is unavailable}}
555
554
}
555
+
556
+ struct BadAccessorAvailability < T> {
557
+ var alwaysUnavailableObservers : T {
558
+ @available ( * , unavailable) // expected-error {{willSet observer for property cannot be marked unavailable with '@available'}}
559
+ willSet { }
560
+
561
+ @available ( * , unavailable) // expected-error {{didSet observer for property cannot be marked unavailable with '@available'}}
562
+ didSet { }
563
+ }
564
+
565
+ var observersUnavailableBeforeSwift99 : T {
566
+ @available ( swift, introduced: 99 ) // expected-error {{willSet observer for property cannot be marked unavailable with '@available'}}
567
+ willSet { }
568
+
569
+ @available ( swift, introduced: 99 ) // expected-error {{didSet observer for property cannot be marked unavailable with '@available'}}
570
+ didSet { }
571
+ }
572
+
573
+ }
Original file line number Diff line number Diff line change @@ -1801,3 +1801,21 @@ class StoredPropertiesWithAvailabilityInClosures {
1801
1801
return 0
1802
1802
} ( )
1803
1803
}
1804
+
1805
+ struct PropertyObservers {
1806
+ var hasPotentiallyUnavailableObservers : Int {
1807
+ @available ( macOS 51 , * ) // expected-error {{willSet observer for property cannot be marked potentially unavailable with '@available'}}
1808
+ willSet { }
1809
+
1810
+ @available ( macOS 51 , * ) // expected-error {{didSet observer for property cannot be marked potentially unavailable with '@available'}}
1811
+ didSet { }
1812
+ }
1813
+
1814
+ var hasObsoletedObservers : Int {
1815
+ @available ( macOS, obsoleted: 10.9 ) // expected-error {{willSet observer for property cannot be marked unavailable with '@available'}}
1816
+ willSet { }
1817
+
1818
+ @available ( macOS, obsoleted: 10.9 ) // expected-error {{didSet observer for property cannot be marked unavailable with '@available'}}
1819
+ didSet { }
1820
+ }
1821
+ }
You can’t perform that action at this time.
0 commit comments