Open
Description
Description
Implicit cast from @Sendable
functions to non-sendable ones doesn't happen in arbitrary expressions.
As SE-302 says:
@Sendable
functions are always subtypes of non-@Sendable
functions, and implicitly convert when needed.
I would expect the following code would work like when replaced with classes and subclasses.
Reproduction
func identity<T>(_ x: T) -> T { x }
func test() {
let sendableClosure: @Sendable (Int) -> (Int) = { $0 }
// ✅
let _: (Int) -> (Int) = sendableClosure
// ❌Conflicting arguments to generic parameter 'T' ('@Sendable (Int) -> Int' vs. '(Int) -> Int')
let _: (Int) -> (Int) = identity(sendableClosure)
// ❌Type of expression is ambiguous without a type annotation
let _: (Int) -> (Int) = true ? sendableClosure : sendableClosure
}
Expected behavior
Perform implicit casts as class and sub-class would do.
Environment
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.4 clang-1600.0.30)
Target: arm64-apple-macosx15.0
Additional information
Swift forums thread: https://forums.swift.org/t/why-is-there-a-type-of-expression-is-ambiguous-without-a-type-annotation-error-when-using-a-ternary-operator-on-inferred-function-types-in-swift/77306
Metadata
Metadata
Assignees
Labels
Area → standard library: The Sendable protocolA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: umbrella label for concurrency language featuresFeature → types: function typesFeature: implicit conversionsArea → compiler: Semantic analysisFeature: typesBug: Unexpected error