Skip to content

AnyObject is Sendable in Argument Position #77292

Open
@sidepelican

Description

@sidepelican

Description

AnyObject is a protocol that is implicitly added to all class types, including non-Sendable classes. Therefore, AnyObject itself should not be considered Sendable.
However, when used as a function argument, AnyObject behaves as though it were Sendable.

Reproduction

func requireSendable(_: some Sendable) {}

func f(v: AnyObject) {
  requireSendable(v) // OK
}

Expected behavior

Should be compile error. like Type 'AnyObject' does not conform to the 'Sendable' protocol

Environment

Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional information

In the return value position, it behaves correctly:

func g(v: AnyObject) -> some Sendable { 
  return v // error: type 'AnyObject' does not conform to the 'Sendable' protocol
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    SendableArea → standard library: The Sendable protocolbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresexpressionsFeature: expressionstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions