Skip to content

Commit 9d3c265

Browse files
authored
Merge pull request #76287 from DougGregor/local-let-of-tuple-type
Expand the tuple "hack" for initializable values to local tuples
2 parents c8a24e5 + ac850bf commit 9d3c265

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7236,8 +7236,14 @@ VarDecl::mutability(const DeclContext *UseDC,
72367236
// declaration. To handle top-level code properly, we look through
72377237
// the TopLevelCode decl on the use (if present) since the vardecl may be
72387238
// one level up.
7239-
if (getDeclContext() == UseDC)
7239+
if (getDeclContext() == UseDC) {
7240+
// Treat values of tuple type as mutable in these contexts, because
7241+
// SILGen wants to see them as lvalues.
7242+
if (getInterfaceType()->is<TupleType>())
7243+
return StorageMutability::Mutable;
7244+
72407245
return StorageMutability::Initializable;
7246+
}
72417247

72427248
if (isa<TopLevelCodeDecl>(UseDC) &&
72437249
getDeclContext() == UseDC->getParent())

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,14 @@ struct S {
16261626
}
16271627
}
16281628

1629+
// rdar://135028163 - trying local 'lets' of tuple type as immutable rvalues, i.e.,
1630+
// the same issue as the above rdar://129031705.
1631+
func tupleAsLocal() {
1632+
let rotation: (Int, Int)
1633+
rotation.0 = 0
1634+
rotation.1 = rotation.0
1635+
}
1636+
16291637
// rdar://128890586: Init accessors
16301638
final class HasInitAccessors {
16311639
private var _ints: [Int] = []

0 commit comments

Comments
 (0)