Skip to content

Commit

Permalink
Add test for @Sendable inference through an optional type.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DougGregor committed Sep 13, 2021
1 parent 03e32c4 commit d6a0b93
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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
Expand Down Expand Up @@ -304,3 +304,14 @@ enum E12<T>: 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
}

0 comments on commit d6a0b93

Please sign in to comment.