Skip to content

Commit 6cdcd00

Browse files
committed
Refactor AreAllStoredPropertiesDefaultInitableRequest for Property Wrappers
Do a bit of cleanup here. Also expand the storage check to query the backing variable for any attached property wrappers. If these are not default-initialized or default initializable then the generated initializer will contain unfixable DI errors. Resolves rdar://58495602
1 parent e18d1e1 commit 6cdcd00

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-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
}

0 commit comments

Comments
 (0)