diff --git a/libguile/eq.c b/libguile/eq.c index 2db4ac022..6cb9bc275 100644 --- a/libguile/eq.c +++ b/libguile/eq.c @@ -104,7 +104,7 @@ real_eqv (double x, double y) } #include -SCM_PRIMITIVE_GENERIC_1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, +SCM_DEFINE1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, (SCM x, SCM y), "Return @code{#t} if @var{x} and @var{y} are the same object, or\n" "for characters and numbers the same value.\n" @@ -173,10 +173,7 @@ SCM_PRIMITIVE_GENERIC_1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, SCM_COMPLEX_IMAG (y))); } } - if (SCM_UNPACK (g_scm_eqv_p)) - return scm_call_generic_2 (g_scm_eqv_p, x, y); - else - return SCM_BOOL_F; + return SCM_BOOL_F; } #undef FUNC_NAME @@ -294,13 +291,20 @@ SCM_PRIMITIVE_GENERIC_1 (scm_equal_p, "equal?", scm_tc7_rpsubr, case scm_tc7_wvect: return scm_i_vector_equal_p (x, y); } + /* Check equality between structs of equal type (see cell-type test above). */ + if (SCM_STRUCTP (x)) + { + if (SCM_INSTANCEP (x)) + goto generic_equal; + else + return scm_i_struct_equalp (x, y); + } - /* Check equality between structs of equal type (see cell-type test above) - that are not GOOPS instances. GOOPS instances are treated via the - generic function. */ - if ((SCM_STRUCTP (x)) && (!SCM_INSTANCEP (x))) - return scm_i_struct_equalp (x, y); - + /* Otherwise just return false. Dispatching to the generic is the wrong thing + here, as we can hit this case for any two objects of the same type that we + think are distinct, like different symbols. */ + return SCM_BOOL_F; + generic_equal: if (SCM_UNPACK (g_scm_equal_p)) return scm_call_generic_2 (g_scm_equal_p, x, y); diff --git a/module/oop/goops.scm b/module/oop/goops.scm index b67c4d4b0..a1af66654 100644 --- a/module/oop/goops.scm +++ b/module/oop/goops.scm @@ -713,7 +713,6 @@ ;;; Methods to compare objects ;;; -(define-method (eqv? x y) #f) (define-method (equal? x y) (eqv? x y)) ;;; diff --git a/test-suite/tests/goops.test b/test-suite/tests/goops.test index 18b2122be..8a06ad99a 100644 --- a/test-suite/tests/goops.test +++ b/test-suite/tests/goops.test @@ -408,18 +408,6 @@ (define o4 (make #:x '(4) #:y '(3))) (not (eqv? o1 o2))) (current-module))) - (pass-if "eqv?" - (eval '(begin - (define-method (eqv? (a ) (b )) - (equal? (x a) (x b))) - (eqv? o1 o2)) - (current-module))) - (pass-if "not eqv?" - (eval '(not (eqv? o2 o3)) - (current-module))) - (pass-if "transfer eqv? => equal?" - (eval '(equal? o1 o2) - (current-module))) (pass-if "equal?" (eval '(begin (define-method (equal? (a ) (b ))