mob/verb/test()
// Checking an object's equivalence to itself
// Bug: doesn't call the overload AND gives the opposite of a desired result
var thing/t = new
world.log << "Calling overload (bugged, doesn't actually call it)"
world.log << "[t ~= t] (0, should be 1)"
world.log << "Calling inverse overload (bugged, doesn't actually call it)"
world.log << "[t ~! t] (1, should be 0)"
world.log << ""
// Checking an object's equivalence with another
var thing/u = new
world.log << "Calling overload"
// Bug: Overload's called 4 times?
world.log << "[t ~= u] (0, should be 0)"
world.log << "Calling inverse overload"
world.log << "[t ~! u] (1, should be 1)"
thing/proc/operator~=(thing/t)
world.log << "Overload called"
return src == t
ID:2374996
Jun 8 2018, 3:51 am
|
|||||||||||||
Resolved
| |||||||||||||
When checking the equivalence of an atom or datum with itself, the operator overload proc isn't called and the result is false. I would expect it to call the overload proc in all cases, and the default result should be true if the objects are actually equal.
|
Jun 8 2018, 9:01 am
|
|
Lummox JR resolved issue with message:
|
Not calling the overloaded operator isn't really a bug but an optimization. However the code was handling this incorrectly, and a fallback case was taking over when it shouldn't have.
I considered pulling out the optimization so the overload is always called, but IMO I don't think it's at all a good idea to set a precedent where ~= can return false when comparing an object to itself, or likewise ~! return true. |