File tree Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Expand file tree Collapse file tree 3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -2483,6 +2483,20 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2483
2483
}
2484
2484
}
2485
2485
}
2486
+
2487
+ // If this is an init accessor property with a default initializer,
2488
+ // make sure that it subsumes initializers of all of its "initializes"
2489
+ // stored properties.
2490
+ if (auto *var = PBD->getSingleVar ()) {
2491
+ auto *initAccessor = var->getAccessor (AccessorKind::Init);
2492
+ if (initAccessor && PBD->isInitialized (0 )) {
2493
+ for (auto *property : initAccessor->getInitializedProperties ()) {
2494
+ auto *propertyBinding = property->getParentPatternBinding ();
2495
+ if (propertyBinding->isInitialized (0 ))
2496
+ propertyBinding->setInitializerSubsumed (0 );
2497
+ }
2498
+ }
2499
+ }
2486
2500
}
2487
2501
2488
2502
void visitSubscriptDecl (SubscriptDecl *SD) {
Original file line number Diff line number Diff line change @@ -479,9 +479,9 @@ func test_memberwise_with_default_args() {
479
479
test_memberwise_with_default_args ( )
480
480
// CHECK: test-memberwise_with_default-1: TestWithoutDefault(_a: -1, _b: 42)
481
481
// CHECK-NEXT: test-memberwise_with_default-2: TestWithoutDefault(_a: 42, _b: -1)
482
- // CHECK-NEXT: test-defaulted-1: TestDefaulted(_a: 0 , _b: 0 )
482
+ // CHECK-NEXT: test-defaulted-1: TestDefaulted(_a: 1 , _b: 2 )
483
483
// CHECK-NEXT: test-defaulted-2: TestDefaulted(_a: 3, _b: 4)
484
- // CHECK-NEXT: test-defaulted-class: ("<<default>> ", 1 )
484
+ // CHECK-NEXT: test-defaulted-class: ("", 42 )
485
485
486
486
func test_init_accessors_without_setters( ) {
487
487
struct TestStruct < T> {
Original file line number Diff line number Diff line change @@ -206,4 +206,31 @@ func test_default_inits() {
206
206
self . x = x
207
207
}
208
208
}
209
+
210
+ class Test3 {
211
+ var _x : Int = 42
212
+ var x : Int = 42 {
213
+ @storageRestrictions ( initializes: _x )
214
+ in it {
215
+ _x = newValue
216
+ }
217
+ get { _x }
218
+ }
219
+
220
+ var _y : String = " "
221
+ var y : String = " " {
222
+ @storageRestrictions ( initializes: _y )
223
+ in it {
224
+ _y = newValue
225
+ }
226
+ get { _y }
227
+ }
228
+
229
+ // CHECK-LABEL: sil private [ossa] @$s23assign_or_init_lowering18test_default_initsyyF5Test3L_CADycfc : $@convention(method) (@owned Test3) -> @owned Test3
230
+ // CHECK: function_ref variable initialization expression of x in Test3 #1 in test_default_inits()
231
+ // CHECK-NOT: function_ref variable initialization expression of _x in Test3 #1 in test_default_inits()
232
+ //
233
+ // CHECK: function_ref variable initialization expression of y in Test3 #1 in test_default_inits()
234
+ // CHECK-NOT: function_ref variable initialization expression of _y in Test3 #1 in test_default_inits()
235
+ }
209
236
}
You can’t perform that action at this time.
0 commit comments