I understand that (in this code) I cannot compare generics that differ in types, but I do not understand the error message. Can anyone explain why it says it cannot compare "two 'Struct<String>' operands" when one is a String and other is an Int? I would expect the error message to be something like this
Error message that is intuitive to me (with my current understanding)
error: binary operator '==' cannot be applied to 'Struct<String>' and 'Struct<Int>' operands
Actual error message
error: binary operator '==' cannot be applied to two 'Struct<String>' operands
Code
struct Struct<T: Equatable> {
let val: T
init(_ val: T) {
self.val = val
}
static func == (lhs: Struct, rhs: Struct) -> Bool{
lhs.val == rhs.val
}
}
print(Struct(0) == Struct(0)) // true
// print(Struct("0") == Struct(0)) // error: binary operator '==' cannot be applied to two 'Struct<String>' operands