The `inout sending` seems not working, it is same as `inout`

inout sending keyword for parameters looks like same as inout, there is no difference between inout and inout sending

protocol NonSendable {}

@MainActor
func sendingInner(_ ns: sending NonSendable) async {}

func sendingOuter(_ ns: sending NonSendable) async {
    await sendingInner(ns)
}


@MainActor
func inoutInner(_ ns: inout NonSendable) async {}

func inoutOuter(_ ns: inout NonSendable) async {
    await inoutInner(&ns) // Compiler Error: Sending 'ns' risks causing data races
}

@MainActor
func inoutSendingInner(_ ns: inout sending NonSendable) async {}
func inoutSendingOuter(_ ns: inout sending NonSendable) async {
    await inoutSendingInner(&ns) // Compiler Error: Sending 'ns' risks causing data races
    // the error should not present here, since sending means the `ns` is in disconnected region, it will pass into @MainActor and wait for pass out

}

I think this is Can't forward `inout sending` argument to another function · Issue #82553 · swiftlang/swift · GitHub

2 Likes