Skip to content

@Sendable function conversions seem unnecessarily restrictive #86203

@mattmassicotte

Description

@mattmassicotte

Description

I cannot see a scenario where these conversions could actually introduce races. My guess would have been that you could never form these functions in an unsafe way in the first place. Maybe I don't see it, but I thought it was at least worth a bug report.

Could it be that the @Sendable-ness is not being taken into account?

Reproduction

class NonSendable {}

let a: @Sendable (NonSendable) -> Void = { _ in }
// warning: Cannot convert '@Sendable (NonSendable) -> Void' to '@Sendable (NonSendable) async -> Void' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol
let b: @Sendable (NonSendable) async -> Void = a

let c: @Sendable () -> NonSendable = { fatalError() }
// warning: Cannot convert '@Sendable () -> NonSendable' to '@Sendable () async -> NonSendable' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol
let d: @Sendable () async -> NonSendable = c

Expected behavior

I think both of these should build warning-free.

Environment

Apple Swift version 6.3-dev (LLVM f6e8f31819e2e67, Swift cecebdd)

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