File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -7404,10 +7404,10 @@ VarDecl::mutability(const DeclContext *UseDC,
7404
7404
if (!isLet ()) {
7405
7405
if (hasInitAccessor ()) {
7406
7406
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(UseDC)) {
7407
- // If we're referencing 'self.', it's initializable .
7407
+ // If we're referencing 'self.', it's mutable .
7408
7408
if (!base ||
7409
7409
(*base && ctor->getImplicitSelfDecl () == (*base)->getDecl ()))
7410
- return StorageMutability::Initializable ;
7410
+ return StorageMutability::Mutable ;
7411
7411
7412
7412
return storageIsMutable (supportsMutation ());
7413
7413
}
@@ -7475,8 +7475,14 @@ VarDecl::mutability(const DeclContext *UseDC,
7475
7475
return StorageMutability::Immutable;
7476
7476
7477
7477
// If we were given a base and it is 'self', it's initializable.
7478
- if (!base || (*base && CD->getImplicitSelfDecl () == (*base)->getDecl ()))
7478
+ if (!base || (*base && CD->getImplicitSelfDecl () == (*base)->getDecl ())) {
7479
+ // Treat values of tuple type as mutable in these contexts, because
7480
+ // SILGen wants to see them as lvalues.
7481
+ if (getInterfaceType ()->is <TupleType>())
7482
+ return StorageMutability::Mutable;
7483
+
7479
7484
return StorageMutability::Initializable;
7485
+ }
7480
7486
7481
7487
return StorageMutability::Immutable;
7482
7488
}
Original file line number Diff line number Diff line change @@ -1614,3 +1614,36 @@ class DerivedWrappedProperty : SomeClass {
1614
1614
} // expected-error {{'super.init' isn't called on all paths before returning from initializer}}
1615
1615
1616
1616
}
1617
+
1618
+ // rdar://129031705 ([error: ... used before being initialized)
1619
+ // Related to treating 'let's as immutable RValues.
1620
+ struct S {
1621
+ let rotation : ( Int , Int )
1622
+
1623
+ init ( ) {
1624
+ rotation. 0 = 0
1625
+ rotation. 1 = rotation. 0
1626
+ }
1627
+ }
1628
+
1629
+ // rdar://128890586: Init accessors
1630
+ final class HasInitAccessors {
1631
+ private var _ints : [ Int ] = [ ]
1632
+
1633
+ private var ints : [ Int ] {
1634
+ @storageRestrictions ( initializes: _ints)
1635
+ init( initialValue) {
1636
+ _ints = initialValue
1637
+ }
1638
+ get {
1639
+ return _ints
1640
+ }
1641
+ set {
1642
+ _ints = newValue
1643
+ }
1644
+ }
1645
+
1646
+ init ( ) {
1647
+ ints. append ( 0 )
1648
+ }
1649
+ }
You can’t perform that action at this time.
0 commit comments