Skip to content

[Concurrency] Classes nested in actors are not semantically final. #72863

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
Apr 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
10 changes: 6 additions & 4 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3701,10 +3701,12 @@ bool ValueDecl::isSemanticallyFinal() const {
return true;
}

// As are members of actor types.
if (auto classDecl = getDeclContext()->getSelfClassDecl()) {
if (classDecl->isAnyActor())
return true;
// As are methods/accessors of actor types.
if (!isa<TypeDecl>(this)) {
if (auto classDecl = getDeclContext()->getSelfClassDecl()) {
if (classDecl->isAnyActor())
return true;
}
}

// For everything else, the same as 'final'.
Expand Down
6 changes: 6 additions & 0 deletions test/Concurrency/sendable_conformance_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,9 @@ extension SendableExtSub: @unchecked Sendable {}
// Still want to know about same-class redundancy
class MultiConformance: @unchecked Sendable {} // expected-note {{'MultiConformance' declares conformance to protocol 'Sendable' here}}
extension MultiConformance: @unchecked Sendable {} // expected-error {{redundant conformance of 'MultiConformance' to protocol 'Sendable'}}

@available(SwiftStdlib 5.1, *)
actor MyActor {
// expected-warning@+1 {{non-final class 'Nested' cannot conform to 'Sendable'; use '@unchecked Sendable'; this is an error in the Swift 6 language mode}}
class Nested: Sendable {}
}