For this protocol one method has a default implementation:
protocol SomeProtocol {
func printValue(_ value: Int)
func printValue(_ value: Int16)
}
extension SomeProtocol {
func printValue(_ value: Int) {
print("\(value) (Int)")
}
}
In a conforming struct I'm trying to implement both methods with a generic parameter:
struct SomeStruct: SomeProtocol {
func printValue(_ value: some Numeric) {
print("\(value) (Numeric)")
}
}
I would have expected that the generic implementation works for both methods, but apparently it is only used for the method that doesn't have a default implementation:
let s = SomeStruct()
s.printValue(1 as Int) // -> 1 (Int)
s.printValue(2 as Int16) // -> 2 (Numeric)
Why ist that? Are the precedence rules documented somewhere?