Can anyone explain why the following error messages differ:
func f(a: Int) { }
func g(a: Int, b: Int) { }
let a: UInt32 = 1
f(a: a) // Cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: a, b: a) // Type of expression is ambiguous without more context
In addition, shouldn't the second complain that there's no matching function found, if it can't figure out that g(_:_) is a close match?
I guess it's about the number of arguments that won't match. The Swift 5.3 compiler gives up after the first error.
func f(a: Int) { }
func g(a: Int, b: Int) { }
let i: UInt32 = 1
f(a: i) // cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: i, b: 123) // cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: 123, b: i) // cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: i, b: i) // type of expression is ambiguous without more context
Playground console
error: MyPlayground.playground:6:6: error: cannot convert value of type 'UInt32' to expected argument type 'Int'
f(a: i)
^
Int( )
error: MyPlayground.playground:7:6: error: cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: i, b: 123)
^
Int( )
error: MyPlayground.playground:8:14: error: cannot convert value of type 'UInt32' to expected argument type 'Int'
g(a: 123, b: i)
^
Int( )
error: MyPlayground.playground:9:1: error: type of expression is ambiguous without more context
g(a: i, b: i)
^~~~~~~~~~~~~
Swift nightly version on compiler explorer seems to be out of date. When you click on the "i" icon, it says c98d04b3f1aa51d which if from 18 August 2020, several snapshots ago