Skip to content

Commit

Permalink
Merge pull request #76287 from DougGregor/local-let-of-tuple-type
Browse files Browse the repository at this point in the history
Expand the tuple "hack" for initializable values to local tuples
  • Loading branch information
DougGregor committed Sep 5, 2024
2 parents c8a24e5 + ac850bf commit 9d3c265
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7236,8 +7236,14 @@ VarDecl::mutability(const DeclContext *UseDC,
// declaration. To handle top-level code properly, we look through
// the TopLevelCode decl on the use (if present) since the vardecl may be
// one level up.
if (getDeclContext() == UseDC)
if (getDeclContext() == UseDC) {
// Treat values of tuple type as mutable in these contexts, because
// SILGen wants to see them as lvalues.
if (getInterfaceType()->is<TupleType>())
return StorageMutability::Mutable;

return StorageMutability::Initializable;
}

if (isa<TopLevelCodeDecl>(UseDC) &&
getDeclContext() == UseDC->getParent())
Expand Down
8 changes: 8 additions & 0 deletions test/SILOptimizer/definite_init_diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,14 @@ struct S {
}
}

// rdar://135028163 - trying local 'lets' of tuple type as immutable rvalues, i.e.,
// the same issue as the above rdar://129031705.
func tupleAsLocal() {
let rotation: (Int, Int)
rotation.0 = 0
rotation.1 = rotation.0
}

// rdar://128890586: Init accessors
final class HasInitAccessors {
private var _ints: [Int] = []
Expand Down

0 comments on commit 9d3c265

Please sign in to comment.