From 482d35d1d79acf1e7c4f64bc016b400fe930baa6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 28 Jun 2023 06:55:12 -0700 Subject: equal: bug: broken equality substitution. * lib.c (equal): Several cases which react to the type of the left argument have a default path which wrongly short-circuits to an early return. All these cases must break through to the logic at the end of the function which tests the right side for a possible equality substitution. * tests/012/struct.tl: One breaking test cases added. equal was found to return nil for two structures that have equal lists as their equality substitute. --- lib.c | 6 +++--- tests/012/struct.tl | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib.c b/lib.c index b5eb4d1e..03e6efb8 100644 --- a/lib.c +++ b/lib.c @@ -4231,7 +4231,7 @@ val equal(val left, val right) default: break; } - return nil; + break; case LCONS: switch (type(right)) { case CONS: @@ -4331,7 +4331,7 @@ val equal(val left, val right) default: return nil; } - return nil; + break; case BGNUM: if (type(right) == BGNUM) { if (mp_cmp(mp(left), mp(right)) == MP_EQ) @@ -4381,7 +4381,7 @@ val equal(val left, val right) if (type(right) == COBJ && left->co.ops == right->co.ops) return left->co.ops->equal(left, right); - return nil; + break; case CPTR: if (type(right) == CPTR && left->co.ops == right->co.ops) return left->co.ops->equal(left, right); diff --git a/tests/012/struct.tl b/tests/012/struct.tl index 93979786..33431780 100644 --- a/tests/012/struct.tl +++ b/tests/012/struct.tl @@ -137,3 +137,11 @@ (test (equal #S(foo) #S(foo)) t) (test (equal #S(foo a 0) #S(foo a 1)) nil) (test (equal #S(bar a 3 b 3) #S(bar a 3 b 3)) t) + +(defstruct eqsub () + key + (:method equal (me) me.key)) + +(test (equal (new eqsub key '(1 2)) + (new eqsub key '(1 2))) + t) -- cgit v1.2.3