Why does the following code yield an "Ambiguous use of 'foo'" compile error? I'd think that the return value makes it clear which one of the foo()
overloads should be called.
Even more interestingly, why does the error disappear if I remove the print("x")
line? What difference does that make?
(Xcode 10.2.1, Swift 5, default build settings for a new project.)
func foo(_: () -> Int) {}
func foo(_: () -> String) {}
func bar() {
foo() {
print("x")
return 42
}
}