fix a bug in is-a?

This bug has been in is-a? since at least 5.2; it turns some errors
into #f. Hopefully no code is actually relying on this bad behavior...
This commit is contained in:
Robby Findler 2013-06-01 07:55:01 -05:00
parent 145f8711c8
commit a931153553
2 changed files with 6 additions and 3 deletions

View File

@ -4651,9 +4651,8 @@ An example
(define (is-a? v c)
(cond
[(not (object? v)) #f]
[(class? c) ((class-object? (class-orig-cls c)) v)]
[(interface? c) (implementation? (object-ref v) c)]
[(class? c) (and (object? v) ((class-object? (class-orig-cls c)) v))]
[(interface? c) (and (object? v) (implementation? (object-ref v) c))]
[else (raise-argument-error 'is-a? "(or/c class? interface?)" 1 v c)]))
(define (subclass? v c)

View File

@ -436,6 +436,10 @@
(test #t is-a? picky (class->interface picky-fish%))
(test #f is-a? red-fish (class->interface picky-fish%))
(err/rt-test (is-a? 1 2) exn:fail?)
(err/rt-test (is-a? red-fish 2) exn:fail?)
(test #f is-a? 11 eater<%>)
(err/rt-test (instantiate fish% () (bad-size 10)) exn:fail:object?)
(err/rt-test (instantiate fish% () (size 10) (size 12)) exn:fail:object?)
(err/rt-test (instantiate fish% (10) (size 12)) exn:fail:object?)