Open
Description
Description
I have two functions; one that takes an async closure and one that doesn't. Then they invoke it, so the first is async itself and the second is not. I would expect that passing in an async closure or not would allow the compiler to select between them, but this does not seem the case.
Steps to reproduce
func foo(_ expression: @autoclosure () -> Int) {
_ = expression()
}
func foo(_ expression: @autoclosure () async -> Int) async {
_ = await expression()
}
foo(1)
await foo(await 1)
Expected behavior
This should compile without issues
Environment
- Swift compiler version info swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.51 clang-1500.1.0.2.2)
Target: arm64-apple-macosx14.0 - Xcode version info
Xcode 15.1
Build version 15C5042i - Deployment target: macOS 14.2
Additional context
$ swiftc test.swift
test.swift:11:11: error: 'await' in an autoclosure that does not support concurrency
await foo(await 1)
^
test.swift:11:1: warning: no 'async' operations occur within 'await' expression
await foo(await 1)
^
error: fatalError
Metadata
Metadata
Assignees
Labels
Feature → attributes: the @autoclosure type attributeFeature → concurrency: asynchronous function aka the async/await patternA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: umbrella label for concurrency language featuresArea → compiler → type checker: Overload resolution (ranking)Area → compiler: Semantic analysisBug: Unexpected error