Skip to content

Commit 940ae92

Browse files
authored
Merge pull request #29943 from CodaFi/cold-storage
[5.2] Refactor AreAllStoredPropertiesDefaultInitableRequest for Property Wrappers
2 parents 245acb0 + 21c3f77 commit 940ae92

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,35 @@ llvm::Expected<bool> AreAllStoredPropertiesDefaultInitableRequest::evaluate(
797797
// synthesize an initial value (e.g. for an optional) then we suppress
798798
// generation of the default initializer.
799799
if (auto pbd = dyn_cast<PatternBindingDecl>(member)) {
800-
if (pbd->hasStorage() && !pbd->isStatic()) {
801-
for (auto idx : range(pbd->getNumPatternEntries())) {
802-
if (pbd->isInitialized(idx)) continue;
800+
// Static variables are irrelevant.
801+
if (pbd->isStatic()) {
802+
continue;
803+
}
803804

805+
for (auto idx : range(pbd->getNumPatternEntries())) {
806+
bool HasStorage = false;
807+
bool CheckDefaultInitializer = true;
808+
pbd->getPattern(idx)->forEachVariable([&](VarDecl *VD) {
804809
// If one of the bound variables is @NSManaged, go ahead no matter
805810
// what.
806-
bool CheckDefaultInitializer = true;
807-
pbd->getPattern(idx)->forEachVariable([&](VarDecl *vd) {
808-
if (vd->getAttrs().hasAttribute<NSManagedAttr>())
809-
CheckDefaultInitializer = false;
810-
});
811-
812-
// If we cannot default initialize the property, we cannot
813-
// synthesize a default initializer for the class.
814-
if (CheckDefaultInitializer && !pbd->isDefaultInitializable())
815-
return false;
816-
}
811+
if (VD->getAttrs().hasAttribute<NSManagedAttr>())
812+
CheckDefaultInitializer = false;
813+
814+
if (VD->hasStorage())
815+
HasStorage = true;
816+
auto *backing = VD->getPropertyWrapperBackingProperty();
817+
if (backing && backing->hasStorage())
818+
HasStorage = true;
819+
});
820+
821+
if (!HasStorage) continue;
822+
823+
if (pbd->isInitialized(idx)) continue;
824+
825+
// If we cannot default initialize the property, we cannot
826+
// synthesize a default initializer for the class.
827+
if (CheckDefaultInitializer && !pbd->isDefaultInitializable())
828+
return false;
817829
}
818830
}
819831
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@propertyWrapper
2+
public struct WrapGod<T> {
3+
private var value: T
4+
5+
public init(wrappedValue: T) {
6+
value = wrappedValue
7+
}
8+
9+
public var wrappedValue: T {
10+
get { value }
11+
set { value = newValue }
12+
}
13+
}
14+
15+
final class TestCaseRunner {}
16+
17+
struct ContentView { // expected-note {{'init(runner:)' declared here}}
18+
@WrapGod var runner: TestCaseRunner
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rdar://58495602: The order used to matter here. If use compiles before def
2+
// then you got a DI error. If def compiles before use then you got a linker error.
3+
4+
// RUN: %target-swift-frontend -emit-sil -verify %s %S/Inputs/di_property_wrappers_errors_multifile_2.swift
5+
// RUN: %target-swift-frontend -emit-sil -verify %S/Inputs/di_property_wrappers_errors_multifile_2.swift %s
6+
7+
let contentView = ContentView() // expected-error {{missing argument for parameter 'runner' in call}}
8+

0 commit comments

Comments
 (0)