Closed
Description
Description
There are false Sendable warnings when passing functions as parameters.
Steps to reproduce
struct Something: Sendable {
@Sendable func doNothing() { }
}
/// ^~~~ The warning is the same, with or without any of the two `Sendable`s.
func doSomething(
_ block: @Sendable (Something) -> (() -> Void)
/// ~~~~~^ `@Sendable` required to trigger the warning.
) {
fatalError()
}
doSomething(Something.doNothing)
/// ^~~~~ Warning: Converting non-sendable function value to '@Sendable (Something) -> (() -> Void)' may introduce data races
The warning goes away if you open the closure instead of directly passing the function:
doSomething { $0.doNothing }
/// ^~~~~ No warnings
Expected behavior
No false warnings.
Environment
Linux CI with swift 5.8 on Ubuntu jammy shows these warnings, as well as my own local environment with Xcode 15 beta 2 and Swift 5.9, so it's fair to say this is not tied to a platform or a Swift version.
~ % swiftc -version
swift-driver version: 1.82.2 Apple Swift version 5.9 (swiftlang-5.9.0.114.10 clang-1500.0.29.1)
Target: arm64-apple-macosx14.0
~ % xcodebuild -version
Xcode 15.0
Build version 15A5161b
~ % uname -a
Darwin Macbook.local 23.0.0 Darwin Kernel Version 23.0.0: Tue Jun 13 21:16:44 PDT 2023; root:xnu-10002.0.116.505.3~3/RELEASE_ARM64_T6000 arm64
Additional Context
- The issue seems to be similar to false
Sendable
warning if SE-299 (Extending Static Member Lookup in Generic Contexts) is used #64388. - We noticed the issue when working on making swift-openapi-runtime compatible with
-strict-concurrency=complete
: Adopt Sendable throughout API to support -strict-concurrency=complete apple/swift-openapi-runtime#22 (comment)- To be clear
minimal
strict-concurrency
is enough for this warning to show up.
- To be clear
Metadata
Metadata
Assignees
Labels
Area → standard library: The Sendable protocolA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: umbrella label for concurrency language featuresFeature → types: function typesFeature: implicit conversionsArea → compiler: Semantic analysisFeature: typesBug: Unexpected warning