Alc
(Alc)
1
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
jrose
(Jordan Rose)
2
Sounds like a compiler bug to me, not a deliberate message. Worth filing!
1 Like
Alc
(Alc)
4
Thank you for replying @jrose, I have created an issue.
PS: deleted the earlier message as I replied to my own question instead of yours
apologies for the double pings.
3 Likes