@@ -3093,7 +3093,7 @@ bool AbstractStorageDecl::isSetterMutating() const {
3093
3093
3094
3094
StorageMutability
3095
3095
AbstractStorageDecl::mutability (const DeclContext *useDC,
3096
- std::optional< const DeclRefExpr *> base ) const {
3096
+ const DeclRefExpr *base) const {
3097
3097
if (auto vd = dyn_cast<VarDecl>(this ))
3098
3098
return vd->mutability (useDC, base);
3099
3099
@@ -3109,10 +3109,8 @@ AbstractStorageDecl::mutability(const DeclContext *useDC,
3109
3109
// / 'optional' storage requirements, which lack support for direct
3110
3110
// / writes in Swift.
3111
3111
StorageMutability
3112
- AbstractStorageDecl::mutabilityInSwift (
3113
- const DeclContext *useDC,
3114
- std::optional<const DeclRefExpr *> base
3115
- ) const {
3112
+ AbstractStorageDecl::mutabilityInSwift (const DeclContext *useDC,
3113
+ const DeclRefExpr *base) const {
3116
3114
// TODO: Writing to an optional storage requirement is not supported in Swift.
3117
3115
if (getAttrs ().hasAttribute <OptionalAttr>()) {
3118
3116
return StorageMutability::Immutable;
@@ -7302,7 +7300,7 @@ static StorageMutability storageIsMutable(bool isMutable) {
7302
7300
// / is a let member in an initializer.
7303
7301
StorageMutability
7304
7302
VarDecl::mutability (const DeclContext *UseDC,
7305
- std::optional< const DeclRefExpr *> base) const {
7303
+ const DeclRefExpr *base) const {
7306
7304
// Parameters are settable or not depending on their ownership convention.
7307
7305
if (auto *PD = dyn_cast<ParamDecl>(this ))
7308
7306
return storageIsMutable (!PD->isImmutableInFunctionBody ());
@@ -7312,12 +7310,9 @@ VarDecl::mutability(const DeclContext *UseDC,
7312
7310
if (!isLet ()) {
7313
7311
if (hasInitAccessor ()) {
7314
7312
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(UseDC)) {
7315
- // If we're referencing 'self.', it's initializable.
7316
- if (!base ||
7317
- (*base && ctor->getImplicitSelfDecl () == (*base)->getDecl ()))
7318
- return StorageMutability::Initializable;
7319
-
7320
- return storageIsMutable (supportsMutation ());
7313
+ if (base && ctor->getImplicitSelfDecl () != base->getDecl ())
7314
+ return storageIsMutable (supportsMutation ());
7315
+ return StorageMutability::Initializable;
7321
7316
}
7322
7317
}
7323
7318
@@ -7375,18 +7370,17 @@ VarDecl::mutability(const DeclContext *UseDC,
7375
7370
getDeclContext ()->getSelfNominalTypeDecl ())
7376
7371
return StorageMutability::Immutable;
7377
7372
7373
+ if (base && CD->getImplicitSelfDecl () != base->getDecl ())
7374
+ return StorageMutability::Immutable;
7375
+
7378
7376
// If this is a convenience initializer (i.e. one that calls
7379
7377
// self.init), then let properties are never mutable in it. They are
7380
7378
// only mutable in designated initializers.
7381
7379
auto initKindAndExpr = CD->getDelegatingOrChainedInitKind ();
7382
7380
if (initKindAndExpr.initKind == BodyInitKind::Delegating)
7383
7381
return StorageMutability::Immutable;
7384
7382
7385
- // If we were given a base and it is 'self', it's initializable.
7386
- if (!base || (*base && CD->getImplicitSelfDecl () == (*base)->getDecl ()))
7387
- return StorageMutability::Initializable;
7388
-
7389
- return StorageMutability::Immutable;
7383
+ return StorageMutability::Initializable;
7390
7384
}
7391
7385
7392
7386
// If the 'let' has a value bound to it but has no PBD, then it is
0 commit comments