Skip to content

Commit ac850bf

Browse files
committed
Expand the tuple "hack" for initializable values to local tuples
Back off treating local lets of tuple type as "initializable", expanding on the narrow carve-out from #74133. Without this, we would reject local lets of tuple type that are initialized piecemeal. Fixes rdar://135028163.
1 parent 92c65f5 commit ac850bf

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
@@ -7587,8 +7587,14 @@ VarDecl::mutability(const DeclContext *UseDC,
75877587
// declaration. To handle top-level code properly, we look through
75887588
// the TopLevelCode decl on the use (if present) since the vardecl may be
75897589
// one level up.
7590-
if (getDeclContext() == UseDC)
7590+
if (getDeclContext() == UseDC) {
7591+
// Treat values of tuple type as mutable in these contexts, because
7592+
// SILGen wants to see them as lvalues.
7593+
if (getInterfaceType()->is<TupleType>())
7594+
return StorageMutability::Mutable;
7595+
75917596
return StorageMutability::Initializable;
7597+
}
75927598

75937599
if (isa<TopLevelCodeDecl>(UseDC) &&
75947600
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)