You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a known bug. The compiler relies on the type of the LHS when type checking a binary operator, and when it sees a primitive type (like f32) on the LHS it tries to use the built-in operation, rather than the overloaded one, which expects the RHS to have the same type as the LHS.
The workaround is to always put your type on the LHS for commutative ops and just use the unsugared method call for the other binary ops.
I got a fix on #19434, but the reviewer is currently busy revamping the associated types feature, so it may take a little longer to land.
I'm trying to define a type that can be added/multiplied with floats.
I've tried overloading
+
like this:But
fails with the following error:
Interestingly,
works just fine.
Is this intended behaviour?
It seems inconsistent that
+
simply ignores the implementation ofAdd
in this case.The text was updated successfully, but these errors were encountered: