Skip to content

sending arguments cannot be sent into actor-isolated implementation #78588

Open
@azarovalex

Description

@azarovalex

Description

When an actor isolated type implements a protocol that has a function with sending arguments, compiler still requires the argument to be Sendable.
My understanding is that the caller should be able to safely pass even non-sendable arguments, since the protocol itself requires "sending" the arguments to the implementation, which should prevent the caller from further accessing the shared mutable state.

I was able to find a similar issue that concerns return values: #76710, also still relevant.

Reproduction

class Test {}

protocol Foo {
    func bar(a: sending Test) async
}

@MainActor
public class FooImpl: Foo {
    func bar(a: sending Test) async {}
    //   `- error: non-sendable parameter type 'Test' cannot be sent from caller of protocol requirement 'bar(a:)' into main actor-isolated implementation
}

Expected behavior

Code compiles.

Environment

Latest main as of today:

Swift version 6.2-dev (LLVM e67c0c37f2274ef, Swift aea6b38)
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