8000 Can't forward `inout sending` argument to another function · Issue #82553 · swiftlang/swift · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Can't forward inout sending argument to another function #82553
Open
@KeithBauerANZ

Description

@KeithBauerANZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0