-
Notifications
You must be signed in to change notification settings - Fork 10.5k
False Sendable data race warnings when passing functions as parameters #67279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is fixed under |
@hborla can confirm, thanks! ~ docker run --rm -it swiftlang/swift:nightly-main-jammy swift -enable-experimental-feature InferSendableFromCaptures -e "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.
) {
print(\"Doing some!\")
}
doSomething(Something.doNothing)"
Doing some! Old: ~ docker run --rm -it swiftlang/swift:nightly-main-jammy swift -e "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.
) {
print(\"Doing some!\")
}
doSomething(Something.doNothing)"
-e:13:23: warning: converting non-sendable function value to '@Sendable (Something) -> (() -> Void)' may introduce data races
doSomething(Something.doNothing)
^
Doing some! |
@hborla It appears there has been a regression re-introducing this warning, based on the latest Docker images: New, emits warnings: ~ docker run --rm -it swiftlang/swift:nightly-main-jammy@sha256:39867f18bb76cf9a02d4e7e9dbbaf9674154675063c1b1d7928daa63d2658ea2 swift -enable-experimental-feature InferSendableFromCaptures -e "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.
) {
print(\"Doing some!\")
}
doSomething(Something.doNothing)"
-e:13:28: warning: converting non-sendable function value to '@Sendable (Something) -> (() -> Void)' may introduce data races
doSomething(Something.doNothing)
^
Doing some! Old, no warnings: ~ docker run --rm -it swiftlang/swift:nightly-main-jammy@sha256:c46884670e329f4f50e6b640be66bdcc16dcb75829878e0e1d22ebc659f3fd3a swift -enable-experimental-feature InferSendableFromCaptures -e "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.
) {
print(\"Doing some!\")
}
doSomething(Something.doNothing)"
Doing some! Notice the hash difference of the nightly-main images. |
@MahdiBM We have promoted the feature to "upcoming" since it has been accepted by the Swift Evolution which means that the flag now is |
@xedin |
Description
There are false Sendable warnings when passing functions as parameters.
Steps to reproduce
The warning goes away if you open the closure instead of directly passing the function:
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.
Additional Context
Sendable
warning if SE-299 (Extending Static Member Lookup in Generic Contexts) is used #64388.-strict-concurrency=complete
: Adopt Sendable throughout API to support -strict-concurrency=complete apple/swift-openapi-runtime#22 (comment)minimal
strict-concurrency
is enough for this warning to show up.The text was updated successfully, but these errors were encountered: