From d6a0b937e40171c7c360acfdf1a909abf04d89ee Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Mon, 13 Sep 2021 14:54:32 -0700 Subject: [PATCH] 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 --- test/Concurrency/concurrent_value_checking.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/Concurrency/concurrent_value_checking.swift b/test/Concurrency/concurrent_value_checking.swift index c0038ff7018ba..41946bbbbbd96 100644 --- a/test/Concurrency/concurrent_value_checking.swift +++ b/test/Concurrency/concurrent_value_checking.swift @@ -1,7 +1,7 @@ // RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency // REQUIRES: concurrency -class NotConcurrent { } // expected-note 17{{class 'NotConcurrent' does not conform to the `Sendable` protocol}} +class NotConcurrent { } // expected-note 18{{class 'NotConcurrent' does not conform to the `Sendable` protocol}} // ---------------------------------------------------------------------- // Sendable restriction on actor operations @@ -304,3 +304,14 @@ enum E12: UnsafeSendable { // expected-warning{{'UnsafeSendable' is deprecate case payload(NotConcurrent) // okay case other(T) // okay } + +// ---------------------------------------------------------------------- +// @Sendable inference through optionals +// ---------------------------------------------------------------------- +func testSendableOptionalInference(nc: NotConcurrent) { + var fn: (@Sendable () -> Void)? = nil + fn = { + print(nc) // expected-warning{{cannot use parameter 'nc' with a non-sendable type 'NotConcurrent' from concurrently-executed code}} + } + _ = fn +}