Skip to content

Commit d6a0b93

Browse files
committed
Add test for @Sendable inference through an optional type.
We previously had a bug where `@Sendable` would not be propagated to a closure when that closure was assigned to a property or passed to a parameter of optional `@Sendable` function type. This has already been fixed in the type checker, but add a test to ensure that we don't regress this behavior. rdar://77789778
1 parent 03e32c4 commit d6a0b93

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/Concurrency/concurrent_value_checking.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency
22
// REQUIRES: concurrency
33

4-
class NotConcurrent { } // expected-note 17{{class 'NotConcurrent' does not conform to the `Sendable` protocol}}
4+
class NotConcurrent { } // expected-note 18{{class 'NotConcurrent' does not conform to the `Sendable` protocol}}
55

66
// ----------------------------------------------------------------------
77
// Sendable restriction on actor operations
@@ -304,3 +304,14 @@ enum E12<T>: UnsafeSendable { // expected-warning{{'UnsafeSendable' is deprecate
304304
case payload(NotConcurrent) // okay
305305
case other(T) // okay
306306
}
307+
308+
// ----------------------------------------------------------------------
309+
// @Sendable inference through optionals
310+
// ----------------------------------------------------------------------
311+
func testSendableOptionalInference(nc: NotConcurrent) {
312+
var fn: (@Sendable () -> Void)? = nil
313+
fn = {
314+
print(nc) // expected-warning{{cannot use parameter 'nc' with a non-sendable type 'NotConcurrent' from concurrently-executed code}}
315+
}
316+
_ = fn
317+
}

0 commit comments

Comments
 (0)