Skip to content

Expand the tuple "hack" for initializable values to local tuples #76287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7587,8 +7587,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish this wasn't a thing... 😭

}

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