- changed milestone to 3.0.4
- changed version to 3.0.3
- changed title to value equality check does not work as described
value equality check does not work as described
In the MobTalkerScript source code (namely the documentation of net.mobtalker.mobtalkerscript.v3.value.MtsValue.isEqual(MtsValue)
), the description of the ==
(equals) operator states that two values are only equal if...
- ...their
equals(Object)
method returnstrue
or... - ...both objects'
__eq
meta methods are the same AND returntrue
.
Currently, the check if the __eq
meta methods are the same is redundant because it always yields false
(as in, they always equal):
MtsValue tagA = getMetaTag( __eq );
if ( tagA.isNil() || !tagA.equals( getMetaTag( __eq ) ) )
return false;
The error is located in line 402. It should be !tagA.equals( b.getMetaTag( __eq ) )
instead of !tagA.equals( getMetaTag( __eq ) )
.
Comments (8)
-
reporter -
reporter - changed milestone to 3.0.5
-
reporter - changed status to open
-
reporter Tested with the following script:
MyClass = {} function MyClass:new() local newInstance = {} setmetatable(newInstance, { __index = self, __eq = function(a, b) return true end }) return newInstance end MyOtherClass = {} function MyOtherClass:new() local newInstance = {} setmetatable(newInstance, { __index = self, __eq = function(a, b) return true end }) return newInstance end instA = MyClass.new() instB = MyOtherClass.new() print(instA == instB)
This script will output
true
with the current implementation, but outputfalse
with line 402 changed. -
reporter - changed status to resolved
Ensure
__eq
meta-methods of both values are compared (fixes#39)→ <<cset d1e266314998>>
-
reporter - changed status to open
Reopening because the behaviour of the value equality check is not equal to how Lua handles it.
Code
C1 = {} function C1:new() local inst = {} setmetatable(inst, { class = 'C1', __index = self, __eq = function (a,b) print('Hello from C1 __eq function') return true end }) return inst end C2 = {} function C2:new() local inst = {} setmetatable(inst, { class = 'C2', __index = self, __eq = function (a,b) print('Hello from C2 __eq function') return false end }) return inst end equals = function (a,b) print('Hello from equals function') return true end C3 = {} function C3:new() local inst = {} setmetatable(inst, { class = 'C3', __index = self, __eq = equals }) return inst end C4 = {} function C4:new() local inst = {} setmetatable(inst, { class = 'C4', __index = self, __eq = equals }) return inst end -- Tests inst1 = C1.new() inst2 = C2.new() inst3 = C3.new() inst4 = C4.new() print('inst1 == inst1? (expected true) ', inst1 == inst1) print('inst2 == inst2? (expected true) ', inst2 == inst2) print('inst3 == inst3? (expected true) ', inst3 == inst3) print('inst4 == inst4? (expected true) ', inst4 == inst4) print('inst1 == inst2? (expected true) ', inst1 == inst2) print('inst2 == inst1? (expected false)', inst2 == inst1) print('inst1 == inst3? (expected true) ', inst1 == inst3) print('inst3 == inst1? (expected true) ', inst3 == inst1) print('inst2 == inst3? (expected false)', inst2 == inst3) print('inst3 == inst2? (expected true) ', inst3 == inst2) print('inst3 == inst4? (expected true) ', inst3 == inst4) print('inst4 == inst3? (expected true) ', inst4 == inst3)
Lua output
inst1 == inst1? (expected true) true inst2 == inst2? (expected true) true inst3 == inst3? (expected true) true inst4 == inst4? (expected true) true Hello from C1 __eq function inst1 == inst2? (expected true) true Hello from C2 __eq function inst2 == inst1? (expected false) false Hello from C1 __eq function inst1 == inst3? (expected true) true Hello from equals function inst3 == inst1? (expected true) true Hello from C2 __eq function inst2 == inst3? (expected false) false Hello from equals function inst3 == inst2? (expected true) true Hello from equals function inst3 == inst4? (expected true) true Hello from equals function inst4 == inst3? (expected true) true
MTS 3.0.4 output
inst1 == inst1? (expected true) true inst2 == inst2? (expected true) true inst3 == inst3? (expected true) true inst4 == inst4? (expected true) true inst1 == inst2? (expected true) false inst2 == inst1? (expected false)false inst1 == inst3? (expected true) false inst3 == inst1? (expected true) false inst2 == inst3? (expected false)false inst3 == inst2? (expected true) false Hello from equals function inst3 == inst4? (expected true) true Hello from equals function inst4 == inst3? (expected true) true
MTS 3.0.6 output
inst1 == inst1? (expected true) true inst2 == inst2? (expected true) true inst3 == inst3? (expected true) true inst4 == inst4? (expected true) true inst1 == inst2? (expected true) false inst2 == inst1? (expected false)false inst1 == inst3? (expected true) false inst3 == inst1? (expected true) false inst2 == inst3? (expected false)false inst3 == inst2? (expected true) false Hello from equals function inst3 == inst4? (expected true) true Hello from equals function inst4 == inst3? (expected true) true
-
reporter -
reporter - changed status to resolved
Fix
#39Reworked regression test for
#39(expected results based on Lua 5.3.3) Removed equality check for __eq meta-methods→ <<cset e5c586c38851>>
- Log in to comment