Operator annotations for comparison operators
The @operator annotation supports nearly all the operator metamethods, except for eq / lt / le. I'd like to be able to annotate that my type are comparable.
I remember why I didn't support these operators. These operations will be adjusted to Boolean values no matter what type of metamethod you returns. Therefore, it is meaningless to declare these operators.
But there's still a difference between values that can be compared and values that can't (at least with the relational comparisons – < <= > >=). While all types can be compared with == ~= (and those with __eq metamethods just invoke custom behaviour when doing so), not all types can be compared with < <= > >=. So I'd like a way to indicate that.
There appears to be two possible states in Lua 5.4. A type that implements __lt also gets __le for free even if it didn't explicitly implement it, so it can be compared with all of < <= > >=. On the other hand, a type that implements __le but not __lt can be compared with <= >= but not with < >. I can't think of any real use-case for this second case, however.
So if you don't like declaring these using @operator, perhaps a new @comparable annotation could be used? It could either be @comparable with no arguments, or @comparable other_type meaning that you can compare values of this type to values of the other type. You could ignore == ~= since they have a default effect even for types that don't implement __eq (comparing by reference).
related discussion #2750