diff --git a/src/value.c b/src/value.c index b7fec17..aabf021 100644 --- a/src/value.c +++ b/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; diff --git a/src/vm.c b/src/vm.c index afbc4c1..a6b403f 100644 --- a/src/vm.c +++ b/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; diff --git a/test/testEqInvert.krk b/test/testEqInvert.krk new file mode 100644 index 0000000..03b8a7b --- /dev/null +++ b/test/testEqInvert.krk @@ -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')) diff --git a/test/testEqInvert.krk.expect b/test/testEqInvert.krk.expect new file mode 100644 index 0000000..59cfc74 --- /dev/null +++ b/test/testEqInvert.krk.expect @@ -0,0 +1,6 @@ +a == b +b == a +False +a == b +b == a +True