Skip to content

Sendable warning produced for unused non-Sendable result value #65463

Open
@itaiferber

Description

@itaiferber

(Migrating details from the Swift Forums)

Description

When Targeted/Complete Sendable checking is enabled, the compiler produces a warning for non-Sendable types crossing actor boundaries as result values, even if the values are explicitly unused.

Steps to reproduce

Compile the following code with Swift 5.8:

@globalActor
final class SomeDedicatedActor {
    actor Actor {}
    static let shared = Actor()
}

@SomeDedicatedActor
func f() async -> [Any] {
    // ...
}

@MainActor
func g() async {
    // ⚠️ Non-sendable type '[Any]' returned by implicitly asynchronous call
    // to global actor 'SomeDedicatedActor'-isolated function cannot cross
    // actor boundary
    _ = await f()
}

Expected behavior

I would expect Swift to

  1. Attempt to elide transferring the resulting value across actor boundaries, and release it on the original actor
  2. Avoid producing the diagnostic

Environment

  • Swift version:
    swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
    Target: arm64-apple-macosx13.0
    
  • Xcode version:
    Xcode 14.3
    Build version 14E222b
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    actorFeature → concurrency: `actor` declarationsactor isolationFeature → concurrency: Actor isolationcompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresfeatureA feature request or implementationimprovementswift 5.8type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions