I assume that there are previous discussions on this, but I couldn't find any, so pointers to such would be appreciated.
As an example, this program will compile and work as expected:
import Foundation
func log(base: Double, of value: Double) -> Double {
return log(value) / log(base)
}
But the exact same function is not accepted by Swift if it's not declared in global scope, for example:
import Foundation
func enclosingFunc() {
func log(base: Double, of value: Double) -> Double {
return log(value) / log(base) // Error: Missing argument for parameter 'of' in call
}
}
And another example:
import Foundation
struct EnclosingType {
static func log(base: Double, of value: Double) -> Double {
return log(value) / log(base) // Error: Use of 'log' nearly matches global function 'log' in module 'Darwin' rather than instance method 'log(base:of:)'
}
}
Related bug reports:
SR-7143
SR-7018
SR-7018 was closed because this works as designed, and there is this explanation:
Overload resolution works on a set of functions in the same context, so in this case once the nested function is found the compiler stops looking for other overloads.
Given this explanation, I can understand the current behavior, but I still think it's very counterintuitive, and I'm not sure I understand why it has to be like this.