Open
Description
Description
This may be related to #81546.
You can't forward an inout sending
argument to another function which takes an inout sending
argument.
Reproduction
import Synchronization func take<Wrapped>( _ optional: inout sending Optional<Wrapped> ) -> sending Optional<Wrapped> { let result = optional optional = nil return result } open class Nonsendable { init() {} } func f() { let m = Mutex(Optional(Nonsendable())) let n = m.withLock { take(&$0)! } print(n) }
swiftc -swift-version 6 ForwardInOutSending.swift
ForwardInOutSending.swift:17:26: error: sending '$0' risks causing data races [#SendingRisksDataRace]
15 | func f() {
16 | let m = Mutex(Optional(Nonsendable()))
17 | let n = m.withLock { take(&$0)! }
| | `- note: 'inout sending' parameter must be reinitialized before function exit with a non-actor isolated value
| |- error: sending '$0' risks causing data races [#SendingRisksDataRace]
| `- note: '$0' used after being passed as a 'sending' parameter; Later uses could race
18 | print(n)
19 | }
[#SendingRisksDataRace]: <https://docs.swift.org/compiler/documentation/diagnostics/sending-risks-data-race>
Expected behavior
I believe this should compile.
Environment
(Xcode 26b2)
swift-driver version: 1.127.5.3 Apple Swift version 6.2 (swiftlang-6.2.0.10.950 clang-1700.3.10.950)
Target: arm64-apple-macosx15.0
Additional information
No response