Compiler does not know how to choose between an async and a non-async version of a function #60469
Labels
async & await
Feature → concurrency: asynchronous function aka the async/await pattern
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
concurrency
Feature: umbrella label for concurrency language features
overload resolution
Area → compiler → type checker: Overload resolution (ranking)
swift 6.0
type checker
Area → compiler: Semantic analysis
unexpected error
Bug: Unexpected error
Acoording to the specification, the compiler should know if an async or non-async version of a function is to be called. This is not the case in the following example, at the line
[1,2,3].forEach { n in show(n) }the compiler gives the error "Ambiguous use of 'forEach'". Only when theawaitkeyword is used in the line after it the compiler knows how to choose between the two versions.Note that if instead of the definition of
forEachin the example a version of it allowing throwing is used, the compiler does know which one to choose, even if the actual code does not throw at all.Environment: macOS 12.5, Xcode 13.4.1, Swift 5.6.1. Also see this topic in the forums.
The text was updated successfully, but these errors were encountered: