Try swapping args to __eq__ on NotImplemented
This commit is contained in:
parent
70d5f1b2b7
commit
729220568e
13
src/value.c
13
src/value.c
@ -201,7 +201,18 @@ int krk_valuesEqual(KrkValue a, KrkValue b) {
|
||||
krk_push(b);
|
||||
KrkValue result = krk_callSimple(OBJECT_VAL(type->_eq),2,0);
|
||||
if (IS_BOOLEAN(result)) return AS_BOOLEAN(result);
|
||||
return 0;
|
||||
if (IS_NOTIMPL(result)) goto _next;
|
||||
return !krk_isFalsey(result);
|
||||
}
|
||||
|
||||
_next:
|
||||
type = krk_getType(b);
|
||||
if (type && type->_eq) {
|
||||
krk_push(b);
|
||||
krk_push(a);
|
||||
KrkValue result = krk_callSimple(OBJECT_VAL(type->_eq),2,0);
|
||||
if (IS_BOOLEAN(result)) return AS_BOOLEAN(result);
|
||||
return !krk_isFalsey(result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
1
src/vm.c
1
src/vm.c
@ -1025,6 +1025,7 @@ int krk_isFalsey(KrkValue value) {
|
||||
case KRK_VAL_NONE: return 1;
|
||||
case KRK_VAL_BOOLEAN: return !AS_BOOLEAN(value);
|
||||
case KRK_VAL_INTEGER: return !AS_INTEGER(value);
|
||||
case KRK_VAL_NOTIMPL: return 1;
|
||||
case KRK_VAL_OBJECT: {
|
||||
switch (AS_OBJECT(value)->type) {
|
||||
case KRK_OBJ_STRING: return !AS_STRING(value)->codesLength;
|
||||
|
9
test/testEqInvert.krk
Normal file
9
test/testEqInvert.krk
Normal file
@ -0,0 +1,9 @@
|
||||
class Foo():
|
||||
def __init__(self, tag):
|
||||
self.tag = tag
|
||||
def __eq__(self, other):
|
||||
print(self.tag,'==',other.tag)
|
||||
return NotImplemented
|
||||
|
||||
print(Foo('a') == Foo('b'))
|
||||
print(Foo('a') != Foo('b'))
|
6
test/testEqInvert.krk.expect
Normal file
6
test/testEqInvert.krk.expect
Normal file
@ -0,0 +1,6 @@
|
||||
a == b
|
||||
b == a
|
||||
False
|
||||
a == b
|
||||
b == a
|
||||
True
|
Loading…
Reference in New Issue
Block a user