Skip to content

Ensure that we warn about non-local non-@unchecked Sendable conformances #41103

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
Jan 31, 2022
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
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3957,10 +3957,9 @@ bool swift::checkSendableConformance(

// Sendable can only be used in the same source file.
auto conformanceDecl = conformanceDC->getAsDecl();
auto behavior = SendableCheckContext(conformanceDC)
auto behavior = SendableCheckContext(conformanceDC, check)
.defaultDiagnosticBehavior();
if (conformanceDC->getParentSourceFile() &&
nominal->getParentSourceFile() &&
conformanceDC->getParentSourceFile() != nominal->getParentSourceFile()) {
conformanceDecl->diagnose(diag::concurrent_value_outside_source_file,
nominal->getDescriptiveKind(),
Expand Down
2 changes: 2 additions & 0 deletions test/Concurrency/Inputs/NonStrictModule.swift
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
public class NonStrictClass { }

public struct NonStrictStruct { }
1 change: 1 addition & 0 deletions test/Concurrency/sendable_conformance_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ actor A10: AsyncThrowingProtocolWithNotSendable {
}

// rdar://86653457 - Crash due to missing Sendable conformances.
// expected-warning@+1{{non-final class 'Klass' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
class Klass<Output: Sendable>: Sendable {}
final class SubKlass: Klass<[S]> {}
public struct S {}
2 changes: 2 additions & 0 deletions test/Concurrency/sendable_module_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ func testA(a: A) async {
// CHECK: note: struct 'StrictStruct' does not conform to the 'Sendable' protocol
// CHECK: note: class 'NonStrictClass' does not conform to the 'Sendable' protocol
}

extension NonStrictStruct: @unchecked Sendable { }
3 changes: 3 additions & 0 deletions test/decl/protocol/special/Actor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ actor A7 {
@available(SwiftStdlib 5.1, *)
class C1: Actor {
// expected-error@-1{{non-actor type 'C1' cannot conform to the 'Actor' protocol}}
// expected-warning@-2{{non-final class 'C1' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
nonisolated var unownedExecutor: UnownedSerialExecutor {
fatalError("")
}
Expand All @@ -52,6 +53,7 @@ class C1: Actor {
@available(SwiftStdlib 5.1, *)
class C2: Actor {
// expected-error@-1{{non-actor type 'C2' cannot conform to the 'Actor' protocol}}
// expected-warning@-2{{non-final class 'C2' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
// FIXME: this should be an isolation violation
var unownedExecutor: UnownedSerialExecutor {
fatalError("")
Expand All @@ -62,6 +64,7 @@ class C2: Actor {
class C3: Actor {
// expected-error@-1{{type 'C3' does not conform to protocol 'Actor'}}
// expected-error@-2{{non-actor type 'C3' cannot conform to the 'Actor' protocol}}
// expected-warning@-3{{non-final class 'C3' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
nonisolated func enqueue(_ job: UnownedJob) { }
}

Expand Down