File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -5321,6 +5321,12 @@ class AbstractStorageDecl : public ValueDecl {
5321
5321
// / with it.
5322
5322
bool hasInitAccessor () const ;
5323
5323
5324
+ // / Return true if this is a property that either has storage
5325
+ // / or init accessor associated with it.
5326
+ bool supportsInitialization () const {
5327
+ return hasStorage () || hasInitAccessor ();
5328
+ }
5329
+
5324
5330
// / Return true if this storage has the basic accessors/capability
5325
5331
// / to be mutated. This is generally constant after the accessors are
5326
5332
// / installed by the parser/importer/whatever.
Original file line number Diff line number Diff line change @@ -2289,7 +2289,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2289
2289
if (PBD->isInitialized (i)) {
2290
2290
// Add the attribute that preserves the "has an initializer" value
2291
2291
// across module generation, as required for TBDGen.
2292
- if (var->hasStorage () &&
2292
+ if (var->supportsInitialization () &&
2293
2293
!var->getAttrs ().hasAttribute <HasInitialValueAttr>()) {
2294
2294
var->getAttrs ().add (new (Ctx)
2295
2295
HasInitialValueAttr (/* IsImplicit=*/ true ));
Original file line number Diff line number Diff line change @@ -1319,9 +1319,11 @@ Optional<unsigned> swift::expandAccessors(
1319
1319
!accessorMacroOnlyIntroducesObservers (macro, roleAttr);
1320
1320
if (foundNonObservingAccessor) {
1321
1321
// If any non-observing accessor was added, mark the initializer as
1322
- // subsumed.
1322
+ // subsumed unless it has init accessor, because the initializer in
1323
+ // such cases could be used for memberwise initialization.
1323
1324
if (auto var = dyn_cast<VarDecl>(storage)) {
1324
- if (auto binding = var->getParentPatternBinding ()) {
1325
+ if (auto binding = var->getParentPatternBinding ();
1326
+ !var->getAccessor (AccessorKind::Init)) {
1325
1327
unsigned index = binding->getPatternEntryIndexForVarDecl (var);
1326
1328
binding->setInitializerSubsumed (index);
1327
1329
}
You can’t perform that action at this time.
0 commit comments