File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1319,6 +1319,12 @@ namespace {
1319
1319
if (!(isAssignmentToSelfParamInInit || VD->getDeclContext ()->isLocalContext ()))
1320
1320
return false ;
1321
1321
1322
+ // If this var isn't in a type context, assignment will always use the setter
1323
+ // if there is an initial value.
1324
+ if (!VD->getDeclContext ()->isTypeContext () &&
1325
+ wrapperInfo.wrappedValuePlaceholder ->getOriginalWrappedValue ())
1326
+ return false ;
1327
+
1322
1328
// If we have a nonmutating setter on a value type, the call
1323
1329
// captures all of 'self' and we cannot rewrite an assignment
1324
1330
// into an initialization.
Original file line number Diff line number Diff line change @@ -51,6 +51,20 @@ func testLocalWrapper() {
51
51
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> () {
52
52
}
53
53
54
+ func testInitialValue( ) {
55
+ // CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local16testInitialValueyyF : $@convention(thin) () -> () {
56
+
57
+ @Wrapper var value : Int = 10
58
+ // CHECK: function_ref @$s22property_wrapper_local16testInitialValueyyF5valueL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
59
+
60
+ value = 15
61
+ // CHECK: function_ref @$s22property_wrapper_local16testInitialValueyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> ()
62
+ // CHECK-NOT: assign_by_wrapper
63
+ // CHECK: return
64
+
65
+ // CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testInitialValueyyF5valueL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int> {
66
+ }
67
+
54
68
@propertyWrapper
55
69
enum Lazy < Value> {
56
70
case uninitialized( ( ) -> Value )
Original file line number Diff line number Diff line change @@ -99,3 +99,23 @@ struct UseWrapperWithAutoclosure {
99
99
} // expected-error{{return from initializer without initializing all stored properties}}
100
100
// expected-note@-1{{'self.wrapped' not initialized}}
101
101
}
102
+
103
+ @propertyWrapper
104
+ struct Wrapper < T> {
105
+ var wrappedValue : T
106
+ }
107
+
108
+ func local( ) {
109
+ var anotherVar : String // expected-note {{variable defined here}}
110
+
111
+ @Wrapper var value = 10 {
112
+ didSet {
113
+ anotherVar = " hello! "
114
+ }
115
+ }
116
+
117
+ value = 15 // expected-error {{variable 'anotherVar' used by function definition before being initialized}}
118
+
119
+ anotherVar = " hello! "
120
+ _ = anotherVar
121
+ }
You can’t perform that action at this time.
0 commit comments