summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-06-06 14:07:29 +0200
committerAndy Wingo <wingo@pobox.com>2009-06-07 00:53:48 +0200
commit4bcc952d4500d484cc43df47e2f7d64e5bc14ff3 (patch)
treea8ba84cda4a39227837a4a42e2a2183679fa1e72
parent12798872ff39e27dbcf90675c3d3554ae27df750 (diff)
downloadguile-4bcc952d4500d484cc43df47e2f7d64e5bc14ff3.tar.gz
fix bug in goops' method cache with rest args
* module/oop/goops/compile.scm (code-table-lookup): Fix a tricky little bug! * test-suite/tests/goops.test ("the method cache"): Add a wee test.
-rw-r--r--module/oop/goops/compile.scm11
-rw-r--r--test-suite/tests/goops.test13
2 files changed, 19 insertions, 5 deletions
diff --git a/module/oop/goops/compile.scm b/module/oop/goops/compile.scm
index e6b13c416..732c1bccd 100644
--- a/module/oop/goops/compile.scm
+++ b/module/oop/goops/compile.scm
@@ -34,11 +34,12 @@
(define code-table-lookup
(letrec ((check-entry (lambda (entry types)
- (if (null? types)
- (and (not (struct? (car entry)))
- entry)
- (and (eq? (car entry) (car types))
- (check-entry (cdr entry) (cdr types)))))))
+ (cond
+ ((not (pair? entry)) (and (null? types) entry))
+ ((null? types) #f)
+ (else
+ (and (eq? (car entry) (car types))
+ (check-entry (cdr entry) (cdr types))))))))
(lambda (code-table types)
(cond ((null? code-table) #f)
((check-entry (car code-table) types))
diff --git a/test-suite/tests/goops.test b/test-suite/tests/goops.test
index 2317228e4..7cdc396aa 100644
--- a/test-suite/tests/goops.test
+++ b/test-suite/tests/goops.test
@@ -261,6 +261,19 @@
(method-more-specific? m1 m2 '()))
(current-module))))
+(with-test-prefix "the method cache"
+ (pass-if "defining a method with a rest arg"
+ (let ((m (current-module)))
+ (eval '(define-method (foo bar . baz)
+ (cons bar baz))
+ m)
+ (eval '(foo 1)
+ m)
+ (eval '(foo 1 2)
+ m)
+ (eval '(equal? (foo 1 2) '(1 2))
+ m))))
+
(with-test-prefix "defining accessors"
(with-test-prefix "define-accessor"