Open
Description
Description
These simple expressions lead to "Type of expression is ambiguous without a type annotation"
Reproduction
None of these can be type checked:
let _: (@MainActor @Sendable () -> Void)? = true ? { } : nil
let _: (@Sendable () -> Void)? = true ? { } : nil
let _: (@MainActor () -> Void)? = true ? { } : nil
These can:
let _: (() -> Void)? = true ? { } : nil
let _: (@MainActor @Sendable () -> Void)? = {}
let _: @MainActor @Sendable () -> Void = {}
let _: (@MainActor @Sendable () -> Void)? = true ? { @MainActor @Sendable in } : nil
Another example that breaks even with the explicit @MainActor @Sendable in
:
func g(_ a: Int) async throws {}
func f() {
let _: (@MainActor @Sendable (Int) async throws -> Void)? = true ? {
@MainActor @Sendable in try await g($0)
} : nil
}
Expected behavior
It compiles.
Environment
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: x86_64-apple-macosx14.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
Area → standard library: The Sendable protocolFeature: Declaration and type attributesA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: umbrella label for concurrency language featuresFeature: expressionsFeature → types: function typesFeature → operators: The ternary operatorArea → compiler: Semantic analysisFeature: typesBug: Unexpected error
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Unable to type-check inline closure expression[/-][+]Unable to type-check inline closure expressions with `@MainActor` and/or `@Sendable`[/+]AnthonyLatsis commentedon Apr 23, 2024
Dropping optionality seems like it would make these simpler to debug:
xedin commentedon Apr 23, 2024
We have a few tests in the suite with this problem already, this is binding inference issue related to ranking between bindings that come from the ternary branches and a contextual type. rdar://125948508 for future reference.
NachoSoto commentedon Jun 19, 2024
Still broken on Swift 6.
NachoSoto commentedon Feb 14, 2025
Still broken on
Swift version 6.0.3