File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -544,6 +544,10 @@ EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
544
544
// / Enable @_lifetime attribute
545
545
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true )
546
546
547
+ // / Excludes 'private' properties with initial values from the memberwise
548
+ // / initializer.
549
+ EXPERIMENTAL_FEATURE(ExcludePrivateFromMemberwiseInit, false )
550
+
547
551
// / Allow macro based aliases to be imported into Swift
548
552
EXPERIMENTAL_FEATURE(ImportMacroAliases, true )
549
553
Original file line number Diff line number Diff line change @@ -8412,10 +8412,17 @@ bool VarDecl::isMemberwiseInitialized(bool preferDeclaredProperties) const {
8412
8412
// If this is a stored property, and not a backing property in a case where
8413
8413
// we only want to see the declared properties, it can be memberwise
8414
8414
// initialized.
8415
- if (hasStorage () && preferDeclaredProperties &&
8416
- isBackingStorageForDeclaredProperty (this ))
8417
- return false ;
8418
-
8415
+ if (hasStorage ()) {
8416
+ if (isBackingStorageForDeclaredProperty (this )) {
8417
+ if (preferDeclaredProperties)
8418
+ return false ;
8419
+ } else if (getASTContext ().LangOpts .hasFeature (Feature::ExcludePrivateFromMemberwiseInit)) {
8420
+ // Private variables with initial values are never memberwise initialized.
8421
+ if (getFormalAccess () == AccessLevel::Private)
8422
+ if (hasInitialValue () || getParentPatternBinding ()->isDefaultInitializable ())
8423
+ return false ;
8424
+ }
8425
+ }
8419
8426
// If this is a computed property with `init` accessor, it's
8420
8427
// memberwise initializable when it could be used to initialize
8421
8428
// other stored properties.
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
127
127
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)
128
128
UNINTERESTING_FEATURE(ImportMacroAliases)
129
129
UNINTERESTING_FEATURE(NoExplicitNonIsolated)
130
+ UNINTERESTING_FEATURE(ExcludePrivateFromMemberwiseInit)
130
131
131
132
// TODO: Return true for inlinable function bodies with module selectors in them
132
133
UNINTERESTING_FEATURE(ModuleSelector)
You can’t perform that action at this time.
0 commit comments