C
Join ServerC#
help
❔ ✅ Using generics that implement IEqualityOperators results in ambiguous call to the == operator
JJansthcirlU2/11/2023
If I have some
Sharplab: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYAMBYAUBgRj1UwAJUCAWAbmLIoDoAZASygEdb96CGA5CAFsApmBYBjAM5diBAJwAKAEQAJYQBt1AexikA7lrDq4AQiUBKGfgDMpScEjjgpALIBDBywAe6ACIBRKAcATwAeABUAJS09XXCAYS11IVhScIA1N2ThAD48UgL9AAtRYTTovVIQOwcIJ10ASX92CCyWYGCAeQAHUQ9DSQiKuOHSACMtJJzGxMFutzFJLSgevuABoZiRrfKYvNxC4tK0xOTBKCqax2BG5tb1dq7esH6wQYSklLjTr/HJ9WmpAas3mi2Wqxe6zeER+52+nzhJwRUH2hz0JTAZQyWQgZWq9mutxabQ6ENe70y2TilNxugmUxmWjmCxYSxWz3JERpwmpOJ5aW5+wA3vlCqhbO5PD4AkEwMEFFEYqQwDsPmcLuJkbzsqQAG588yigoig6HQoVUgAXmVMS4ZsKsIu1s16rt9tI3Kter5boKAF88EbyLZFZULULSABzYTAaikNjtOMB00FcVI9WkR2kCPR2PxqCJ0jJw5p7E6z05mNxyRVot4ZPEWwYVweMTSwIhU7qYROFjLTaxdO/Mu41GFdHHUOXAl1G5Au4kp5rDah7aD+kAxnMsHs5fQ1e7QehscFCeYofnae1erz4kPUkcqHvR3w9V0/6A4FM0Gs8GPlcvheqRqikJ5HOeI54lcs5Evcjxkk+XJ8tqtJ/AyQIgiybIISu3IofykHCkG3RiPqwBlJibhwMs6jBKQrD2KEkptn4HZygOr7DoKOSkAA+sIsosMI0iBimwYtlKrGysEXY9sAfZQAohpiSa7p8QJnjCV6UDCHoSm+nWuBBqWnrAEUrIANpTiqR5Zi6KQALpBqp7q5laPH8YJwkMAAymwkbdgoZSWjxwgMBalrWjZpAAGQxaQYVZpFpD2ec5gMNyBmHDWwBBocLlqQUIR5e6BWFYc+pgAl0lep5mmSL5/mBcFoXhTEDALuokgKDZ5ixfFiXIh1d7dalUDmJYJXlRpcoZXyXr6tkWXusW5UpR44hFKQCj+F44jCN08nLMpa3ZlNhV1WI3kAIJwHACg6XpNm6GNuiLbiE3Lfaq3fUGyZ+kAA
T: IEqualityOperators<T, T, bool>
and use a LINQ query such as myTs.FirstOrDefault(t => t == otherT)
, I get an error saying that the ==
operator call is ambiguous. How can I make sure the equality check happens through the IEqualityOperators
interface and not using the reference equals operator?Sharplab: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYAMBYAUBgRj1UwAJUCAWAbmLIoDoAZASygEdb96CGA5CAFsApmBYBjAM5diBAJwAKAEQAJYQBt1AexikA7lrDq4AQiUBKGfgDMpScEjjgpALIBDBywAe6ACIBRKAcATwAeABUAJS09XXCAYS11IVhScIA1N2ThAD48UgL9AAtRYTTovVIQOwcIJ10ASX92CCyWYGCAeQAHUQ9DSQiKuOHSACMtJJzGxMFutzFJLSgevuABoZiRrfKYvNxC4tK0xOTBKCqax2BG5tb1dq7esH6wQYSklLjTr/HJ9WmpAas3mi2Wqxe6zeER+52+nzhJwRUH2hz0JTAZQyWQgZWq9mutxabQ6ENe70y2TilNxugmUxmWjmCxYSxWz3JERpwmpOJ5aW5+wA3vlCqhbO5PD4AkEwMEFFEYqQwDsPmcLuJkbzsqQAG588yigoig6HQoVUgAXmVMS4ZsKsIu1s16rt9tI3Kter5boKAF88EbyLZFZULULSABzYTAaikNjtOMB00FcVI9WkR2kCPR2PxqCJ0jJw5p7E6z05mNxyRVot4ZPEWwYVweMTSwIhU7qYROFjLTaxdO/Mu41GFdHHUOXAl1G5Au4kp5rDah7aD+kAxnMsHs5fQ1e7QehscFCeYofnae1erz4kPUkcqHvR3w9V0/6A4FM0Gs8GPlcvheqRqikJ5HOeI54lcs5Evcjxkk+XJ8tqtJ/AyQIgiybIISu3IofykHCkG3RiPqwBlJibhwMs6jBKQrD2KEkptn4HZygOr7DoKOSkAA+sIsosMI0iBimwYtlKrGysEXY9sAfZQAohpiSa7p8QJnjCV6UDCHoSm+nWuBBqWnrAEUrIANpTiqR5Zi6KQALpBqp7q5laPH8YJwkMAAymwkbdgoZSWjxwgMBalrWjZpAAGQxaQYVZpFpD2ec5gMNyBmHDWwBBocLlqQUIR5e6BWFYc+pgAl0lep5mmSL5/mBcFoXhTEDALuokgKDZ5ixfFiXIh1d7dalUDmJYJXlRpcoZXyXr6tkWXusW5UpR44hFKQCj+F44jCN08nLMpa3ZlNhV1WI3kAIJwHACg6XpNm6GNuiLbiE3Lfaq3fUGyZ+kAA
Pphaseshift2/11/2023
show code and show exact error please
JJansthcirlU2/11/2023
hey sorry for the slow reply, I can't reproduce the error on my machine somehow, it happened on my work pc, I'll update my post later
AAccord2/12/2023
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
JJansthcirlU2/13/2023
Also tagging @tannergooding cause it's a numerics thing
Ttannergooding2/13/2023
IComparisonOperators
implies IEqualityOperators
so you've defined both
IEqualityOperators<TRow, TRow, bool>
and IEqualityOperators<TRow, TRow, TRow>
therefore overloading by return type which is not normally supported
Ttannergooding2/13/2023
thus C# cannot determine which of the two you want
JJansthcirlU2/13/2023
Oh I see, I should've checked
JJansthcirlU2/13/2023
So just comparison operators is enough then
Ttannergooding2/13/2023
it depends.
How are you expecting
How are you expecting
IComparisonOperators
to work given the return type is TRow
and not bool
?JJansthcirlU2/13/2023
Hmm, good question, I guess the element that precedes the other should be returned, similar to how
IComparable
returns its intsTtannergooding2/13/2023
There are some cases where that can make sense, such as
which return a per element mask
Vector128<T> GreaterThan(Vector128<T>, Vector128<T>)
which return a per element mask
Ttannergooding2/13/2023
but, you should typically have that as a different API so that the normal usage of
x > y
works in typical user expressions/etcJJansthcirlU2/13/2023
I see, I guess if I'm not working with numbers explicitly I could stick to just equality stuff
JJansthcirlU2/13/2023
Thanks!
JJansthcirlU2/13/2023
!close
AAccord2/13/2023
Closed!
AAccord2/14/2023
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.