Skip to content

False Sendable data race warnings when passing functions as parameters #67279

Closed
@MahdiBM

Description

@MahdiBM

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

Metadata

Metadata

Assignees

Labels

SendableArea → standard library: The Sendable protocolbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresfunction typesFeature → types: function typesimplicit conversionsFeature: implicit conversionsswift 5.9type checkerArea → compiler: Semantic analysistypesFeature: typesunexpected warningBug: Unexpected warning

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions