Skip to content

Swift fails to correctly select between async and regular overload #69489

Open
@saagarjha

Description

@saagarjha

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

No one assigned

    Labels

    @autoclosureFeature → attributes: the @autoclosure type attributeasync & awaitFeature → concurrency: asynchronous function aka the async/await patternbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresoverload resolutionArea → compiler → type checker: Overload resolution (ranking)swift 6.0type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions