I have the following function
func greater<T: Comparable>(_ lhs: T, rhs: T) -> some Comparable {
lhs > rhs ? lhs : rhs
}
But when I try the following I get an error
greater(greater(1, 2), 3) // Cannot convert value of type 'Int' to expected argument type 'some Comparable'
I understand the error but why is not the compiler able to infer that both types are actually Int
s?
When could that function possibly return another type than what was the input type so redeclare it as
or another way to look at it, when returning
some Comparable
we could change the function to below and it would still be valid