File tree Expand file tree Collapse file tree 6 files changed +47
-5
lines changed Expand file tree Collapse file tree 6 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -5390,6 +5390,10 @@ class VarDecl : public AbstractStorageDecl {
5390
5390
// / an attached property wrapper.
5391
5391
VarDecl *getPropertyWrapperWrappedValueVar () const ;
5392
5392
5393
+ // / Return true if this property either has storage or has an attached property
5394
+ // / wrapper that has storage.
5395
+ bool hasStorageOrWrapsStorage () const ;
5396
+
5393
5397
// / Visit all auxiliary declarations to this VarDecl.
5394
5398
// /
5395
5399
// / An auxiliary declaration is a declaration synthesized by the compiler to support
Original file line number Diff line number Diff line change @@ -6446,6 +6446,20 @@ VarDecl *VarDecl::getPropertyWrapperWrappedValueVar() const {
6446
6446
return getPropertyWrapperAuxiliaryVariables ().localWrappedValueVar ;
6447
6447
}
6448
6448
6449
+ bool VarDecl::hasStorageOrWrapsStorage () const {
6450
+ if (hasStorage ())
6451
+ return true ;
6452
+
6453
+ if (getAttrs ().hasAttribute <LazyAttr>())
6454
+ return true ;
6455
+
6456
+ auto *backing = getPropertyWrapperBackingProperty ();
6457
+ if (backing && backing->hasStorage ())
6458
+ return true ;
6459
+
6460
+ return false ;
6461
+ }
6462
+
6449
6463
void VarDecl::visitAuxiliaryDecls (llvm::function_ref<void (VarDecl *)> visit) const {
6450
6464
if (getDeclContext ()->isTypeContext () || isImplicit ())
6451
6465
return ;
Original file line number Diff line number Diff line change @@ -928,10 +928,7 @@ bool AreAllStoredPropertiesDefaultInitableRequest::evaluate(
928
928
if (VD->getAttrs ().hasAttribute <NSManagedAttr>())
929
929
CheckDefaultInitializer = false ;
930
930
931
- if (VD->hasStorage ())
932
- HasStorage = true ;
933
- auto *backing = VD->getPropertyWrapperBackingProperty ();
934
- if (backing && backing->hasStorage ())
931
+ if (VD->hasStorageOrWrapsStorage ())
935
932
HasStorage = true ;
936
933
});
937
934
Original file line number Diff line number Diff line change @@ -3562,7 +3562,7 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
3562
3562
auto *DC = D->getDeclContext ();
3563
3563
3564
3564
if (auto *VD = dyn_cast<VarDecl>(D)) {
3565
- if (!VD->hasStorage ())
3565
+ if (!VD->hasStorageOrWrapsStorage ())
3566
3566
return None;
3567
3567
3568
3568
// Do not permit potential availability of script-mode global variables;
Original file line number Diff line number Diff line change 8
8
@available ( macOS 50 , * )
9
9
struct NewStruct { }
10
10
11
+ @available ( macOS 50 , * )
12
+ @propertyWrapper
13
+ struct NewPropertyWrapper < Value> {
14
+ var wrappedValue : Value
15
+ }
16
+
11
17
@available ( macOS 50 , * )
12
18
struct GoodReferenceStruct {
13
19
var x : NewStruct
20
+ @NewPropertyWrapper var y : Int
21
+ lazy var z : Int = 42
14
22
}
15
23
16
24
@available ( macOS 50 , * )
17
25
struct GoodNestedReferenceStruct {
18
26
struct Inner {
19
27
var x : NewStruct
28
+ @NewPropertyWrapper var y : Int
29
+ lazy var z : Int = 42
20
30
}
21
31
}
22
32
23
33
struct BadReferenceStruct1 {
24
34
// expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
25
35
@available ( macOS 50 , * )
26
36
var x : NewStruct
37
+
38
+ // expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
39
+ @available ( macOS 50 , * )
40
+ @NewPropertyWrapper var y : Int
41
+
42
+ // expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
43
+ @available ( macOS 50 , * )
44
+ lazy var z : Int = 42
27
45
}
28
46
29
47
@available ( macOS 40 , * )
30
48
struct BadReferenceStruct2 {
31
49
// expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
32
50
@available ( macOS 50 , * )
33
51
var x : NewStruct
52
+
53
+ // expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
54
+ @available ( macOS 50 , * )
55
+ @NewPropertyWrapper var y : Int
56
+
57
+ // expected-error@+1 {{stored properties cannot be marked potentially unavailable with '@available'}}
58
+ @available ( macOS 50 , * )
59
+ lazy var z : Int = 42
34
60
}
35
61
36
62
// The same behavior should hold for enum elements with payloads.
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ class AcceptableDynamic {
86
86
}
87
87
88
88
// mainly just some sanity checks
89
+ // expected-error@+1 {{class 'Misc' has no initializers}}
89
90
class Misc {
90
91
// expected-error@+2 {{'lazy' cannot be used on a computed property}}
91
92
// expected-error@+1 {{lazy properties must have an initializer}}
You can’t perform that action at this time.
0 commit comments