1 ;;;; miscellaneous side-effectful tests of CLOS
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (load "compiler-test-util.lisp")
15 (defpackage "CLOS-IMPURE"
16 (:use
"CL" "ASSERTOID" "TEST-UTIL" "COMPILER-TEST-UTIL"))
17 (in-package "CLOS-IMPURE")
19 ;;; It should be possible to do DEFGENERIC and DEFMETHOD referring to
20 ;;; structure types defined earlier in the file.
21 (defstruct struct-a x y
)
22 (defstruct struct-b x y z
)
23 (defmethod wiggle ((a struct-a
))
26 (defgeneric jiggle
(arg))
27 (defmethod jiggle ((a struct-a
))
30 (defmethod jiggle ((b struct-b
))
35 (with-test (:name
(defmethod defstruct :same-file
))
36 (assert (= (wiggle (make-struct-a :x
6 :y
5))
37 (jiggle (make-struct-b :x
19 :y
6 :z
2)))))
39 ;;; Compiling DEFGENERIC should prevent "undefined function" style
40 ;;; warnings from code within the same file.
41 (defgeneric gf-defined-in-this-file
(x y
))
42 (defun function-using-gf-defined-in-this-file (x y n
)
44 (gf-defined-in-this-file x y
)))
46 ;;; Until Martin Atzmueller ported Pierre Mai's CMU CL fixes in
47 ;;; sbcl-0.6.12.25, the implementation of NO-APPLICABLE-METHOD was
48 ;;; broken in such a way that the code here would signal an error.
49 (defgeneric zut-n-a-m
(a b c
))
50 (defmethod no-applicable-method ((zut-n-a-m (eql #'zut-n-a-m
)) &rest args
)
51 :no-applicable-method
)
52 (with-test (:name no-applicable-method
)
53 (assert (eq :no-applicable-method
(zut-n-a-m 1 2 3))))
55 ;;; bug reported and fixed by Alexey Dejneka sbcl-devel 2001-09-10:
56 ;;; This DEFGENERIC shouldn't cause an error.
57 (defgeneric ad-gf
(a) (:method
:around
(x) x
))
59 ;;; DEFGENERIC and DEFMETHOD shouldn't accept &REST when it's not
60 ;;; followed by a variable:
61 ;;; e.g. (DEFMETHOD FOO ((X T) &REST) NIL) should signal an error.
62 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
63 (defmacro expect-error
(&body body
)
64 `(multiple-value-bind (res condition
)
65 (ignore-errors (progn ,@body
))
66 (declare (ignore res
))
67 (typep condition
'error
))))
68 (assert (expect-error (defmethod foo0 ((x t
) &rest
) nil
)))
69 (assert (expect-error (defgeneric foo1
(x &rest
))))
70 (assert (expect-error (defgeneric foo2
(x a
&rest
))))
71 (defgeneric foo3
(x &rest y
))
72 (defmethod foo3 ((x t
) &rest y
) nil
)
73 (defmethod foo4 ((x t
) &rest z
&key y
) nil
)
74 (defgeneric foo4
(x &rest z
&key y
))
75 (assert (expect-error (defgeneric foo5
(x &rest
))))
76 (assert (expect-error (defmethod foo6 (x &rest
))))
78 ;;; legal method specializers
79 (defclass bug-525916-1
() ())
80 (defclass bug-525916-2
() ())
81 (with-test (:name
(defmethod :specializer-syntax
:bug-525916
))
82 (assert (expect-error (defmethod invalid ((arg)) arg
)))
83 (assert (expect-error (defmethod invalid (nil) 1)))
84 (assert (expect-error (defmethod invalid ((arg . bug-525916-1
)) arg
)))
85 (assert (expect-error (defmethod invalid ((arg bug-525916-1 bug-525916-2
)) arg
))))
87 ;;; more lambda-list checking
89 ;;; DEFGENERIC lambda lists are subject to various limitations, as per
90 ;;; section 3.4.2 of the ANSI spec. Since Alexey Dejneka's patch for
91 ;;; bug 191-b ca. sbcl-0.7.22, these limitations should be enforced.
92 (with-test (:name
(defgeneric :lambda-list
))
93 (labels ((coerce-to-boolean (x)
95 (test-case (lambda-list
97 expected-failure-p expected-warnings-p message
)
98 (declare (type boolean expected-failure-p
))
99 (format t
"~&trying ~S~%" lambda-list
)
100 (let ((*error-output
* (make-string-output-stream) ))
101 (multiple-value-bind (fun warnings-p failure-p
)
102 (compile nil
`(lambda () (defgeneric ,(gensym) ,lambda-list
)))
103 (declare (ignore fun
))
104 (assert (eq (coerce-to-boolean failure-p
) expected-failure-p
))
105 (assert (eq (coerce-to-boolean warnings-p
) expected-warnings-p
))
107 (assert (search message
(get-output-stream-string
108 *error-output
*))))))))
110 (test-case '("a" #p
"b")
111 t t
"Required argument is not a symbol: \"a\"")
114 ;; forbidden default or supplied-p for &OPTIONAL or &KEY arguments
115 (test-case '(x &optional
(y 0))
116 t t
"invalid (Y 0) in the generic function lambda list")
117 (test-case '(x &optional y
))
118 (test-case '(x y
&key
(z :z z-p
))
119 t t
"invalid (Z :Z Z-P) in the generic function lambda list")
120 (test-case '(x y
&key z
))
121 (test-case '(x &optional
(y 0) &key z
)
122 t t
"invalid (Y 0) in the generic function lambda list")
123 (test-case '(x &optional y
&key z
)
124 nil t
"&OPTIONAL and &KEY found in the same lambda list")
125 (test-case '(x &optional y
&key
(z :z
))
126 t t
"invalid (Z :Z) in the generic function lambda list")
127 (test-case '(x &optional y
&key z
)
128 nil t
"&OPTIONAL and &KEY found in the same lambda list")
129 (test-case '(&optional
&key
(k :k k-p
))
130 t t
"invalid (K :K K-P)")
131 (test-case '(&optional
&key k
))
133 (test-case '(x y z
&optional a
&aux g h
)
134 t t
"&AUX is not allowed in a generic function lambda list")
135 (test-case '(x y z
&optional a
))
137 t t
"&AUX is not allowed in a generic function lambda list")
139 ;; also can't use bogoDEFMETHODish type-qualifier-ish decorations
140 ;; on required arguments
141 (test-case '((arg t
))
142 t t
"Required argument is not a symbol: (ARG T)")
146 ;;; Explicit :metaclass option with structure-class and
149 (defclass structure-class-foo1
() () (:metaclass cl
:structure-class
))
150 (defclass structure-class-foo2
(structure-class-foo1)
151 () (:metaclass cl
:structure-class
))
152 (with-test (:name
(defclass :metaclass cl
:structure-class
))
153 (assert (typep (class-of (make-instance 'structure-class-foo1
))
155 (assert (typep (make-instance 'structure-class-foo1
) 'structure-class-foo1
))
156 (assert (typep (class-of (make-instance 'structure-class-foo2
))
158 (assert (typep (make-instance 'structure-class-foo2
) 'structure-class-foo2
)))
160 (defclass standard-class-foo1
() () (:metaclass cl
:standard-class
))
161 (defclass standard-class-foo2
(standard-class-foo1)
162 () (:metaclass cl
:standard-class
))
163 (with-test (:name
(defclass :metaclass cl
:standard-class
))
164 (assert (typep (make-instance 'standard-class-foo1
) 'standard-class-foo1
))
165 (assert (typep (make-instance 'standard-class-foo2
) 'standard-class-foo2
)))
167 ;;; DEFGENERIC's blow-away-old-methods behavior is specified to have
168 ;;; special hacks to distinguish between defined-with-DEFGENERIC-:METHOD
169 ;;; methods and defined-with-DEFMETHOD methods, so that reLOADing
170 ;;; DEFGENERIC-containing files does the right thing instead of
171 ;;; randomly slicing your generic functions. (APD made this work
172 ;;; in sbcl-0.7.0.2.)
173 (defgeneric born-to-be-redefined
(x)
174 (:method
((x integer
))
176 (defmethod born-to-be-redefined ((x real
))
178 (assert (eq (born-to-be-redefined 1) 'integer
))
179 (defgeneric born-to-be-redefined
(x))
180 (assert (eq (born-to-be-redefined 1) 'real
)) ; failed until sbcl-0.7.0.2
181 (defgeneric born-to-be-redefined
(x)
182 (:method
((x integer
))
184 (defmethod born-to-be-redefined ((x integer
))
186 (assert (eq (born-to-be-redefined 1) 'int
))
187 (defgeneric born-to-be-redefined
(x))
188 (assert (eq (born-to-be-redefined 1) 'int
))
190 ;;; In the removal of ITERATE from SB-PCL, a bug was introduced
191 ;;; preventing forward-references and also CHANGE-CLASS (which
192 ;;; forward-references used interally) from working properly.
194 ;;; One symptom was reported by Brian Spilsbury (sbcl-devel
195 ;;; 2002-04-08), and another on IRC by Dan Barlow simultaneously.
196 ;;; Better check that it doesn't happen again.
198 ;;; Some more CHANGE-CLASS testing (which only applies to the now
199 ;;; ANSI-compliant version) thanks to Espen Johnsen)
201 ;; First, the forward references:
202 (defclass forward-ref-a
(forward-ref-b) ())
203 (defclass forward-ref-b
() ())
204 ;; (a couple more complicated examples found by Paul Dietz' test
206 (defclass forward-ref-c1
(forward-ref-c2) ())
207 (defclass forward-ref-c2
(forward-ref-c3) ())
209 (defclass forward-ref-d1
(forward-ref-d2 forward-ref-d3
)
211 (defclass forward-ref-d2
(forward-ref-d4 forward-ref-d5
)
215 (defun change-class-test-case (spec)
216 (destructuring-bind (from-class from-initargs
220 (let ((from (typecase from-class
222 (apply #'make-instance from-class from-initargs
))
223 ((cons (eql :class
) (cons symbol
))
224 (find-class (second from-class
))))))
226 (apply #'change-class from to-class to-initargs
))
227 ;; These local functions make ASSERT produce better error
229 (slot-value-equal (instance name value expected
)
230 (declare (ignore instance name
))
231 (equal value expected
))
232 (slot-not-bound (instance name
)
233 (not (slot-boundp instance name
))))
236 (assert-error (change)))
238 (assert-error (change) type-error
))
241 (loop :for
(name value
) :in expected-slots
244 (assert (slot-not-bound to name
)))
248 to name
(slot-value to name
) value
))))))))))))
250 (defclass change-class.smoke
.1 ()
251 ((foo :initarg
:foo
)))
252 (defclass change-class.smoke
.2 (change-class.smoke
.1) ())
253 (defclass change-class.smoke
.3 (change-class.smoke
.1)
254 ((foo :initarg
:foo
)))
255 (defclass change-class.smoke
.4 ()
256 ((foo :initarg
:foo
) (bar :initarg
:bar
)))
257 (defclass change-class.smoke
.5 ()
258 ((a :initarg
:a
) (b :initarg
:b
) (c :initarg
:c
)))
259 (defclass change-class.smoke
.6 () ())
261 (with-test (:name
(change-class :smoke
))
263 #'change-class-test-case
264 '(;; Test unbound slots.
265 (change-class.smoke
.1 () change-class.smoke
.1 ()
267 (change-class.smoke
.1 () change-class.smoke
.2 ()
269 (change-class.smoke
.1 () change-class.smoke
.3 ()
271 (change-class.smoke
.1 () change-class.smoke
.4 ()
272 ((foo :unbound
) (bar :unbound
)))
273 (change-class.smoke
.4 (:bar
1) change-class.smoke
.1 ()
276 ;; Bound slots are retained.
277 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.1 ()
279 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.2 ()
281 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.3 ()
283 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.4 ()
284 ((foo :baz
) (bar :unbound
)))
285 (change-class.smoke
.4 (:foo
:baz
) change-class.smoke
.1 ()
289 (change-class.smoke
.5 (:a
1 :b
2 :c
3) change-class.smoke
.5 ()
292 ;; Original test by Espen Johnsen
293 (change-class.smoke
.1 (:foo
1) change-class.smoke
.4 (:bar
2)
296 ;; Cannot change objects into metaobjects.
297 (change-class.smoke
.6 () class
()
299 (change-class.smoke
.6 () generic-function
()
301 (change-class.smoke
.6 () method
()
303 (change-class.smoke
.6 () slot-definition
()
306 ;; Test for type-checking
308 (locally (declare (optimize (safety 3))) ; force slot type-checking
309 (defclass change-class.type-check
.1 ()
310 ((foo :initarg
:foo
:type real
)))
311 (defclass change-class.type-check
.2 ()
312 ((foo :initarg
:foo
:type integer
))))
314 (with-test (:name
(change-class :type-check
))
316 #'change-class-test-case
317 '(;; These are allowed.
318 (change-class.type-check
.1 () change-class.type-check
.2 ()
320 (change-class.type-check
.1 (:foo
1) change-class.type-check
.2 ()
322 (change-class.type-check
.1 (:foo
1.0) change-class.type-check
.2 (:foo
2)
325 ;; These are not allowed.
326 (change-class.type-check
.1 () change-class.type-check
.2 (:foo
1.0)
328 (change-class.type-check
.1 (:foo
1.0) change-class.type-check
.2 ()
331 ;; Type-mismatches should be recoverable via USE-VALUE restart.
332 (let* ((from (make-instance 'change-class.type-check
.1 :foo
1.0))
333 (to (handler-bind ((type-error (lambda (condition)
334 (declare (ignore condition
))
336 (change-class from
'change-class.type-check
.2))))
337 (assert (equal (slot-value to
'foo
) 3))))
339 ;; Test interaction with initforms and -args
341 (defclass change-class.initforms
.1 ()
343 (defclass change-class.initforms
.2 ()
344 ((foo :initarg
:foo
)))
345 (defclass change-class.initforms
.3 ()
346 ((foo :initarg
:foo
:initform
:bar
)))
347 (defclass change-class.initforms
.4 ()
348 ((foo :initarg
:foo
))
352 (with-test (:name
(change-class :initforms
))
354 #'change-class-test-case
355 '(;; Initialization of added slot.
356 (change-class.initforms
.1 () change-class.initforms
.3 ()
358 (change-class.initforms
.1 () change-class.initforms
.3 (:foo
:fez
)
360 (change-class.initforms
.1 () change-class.initforms
.4 ()
361 ((foo :unbound
))) ; default initargs are not used
362 (change-class.initforms
.1 () change-class.initforms
.4 (:foo
:fez
)
365 ;; Unbound slot remains unbound.
366 (change-class.initforms
.2 () change-class.initforms
.3 ()
368 (change-class.initforms
.2 () change-class.initforms
.3 (:foo
:fez
)
370 (change-class.initforms
.2 () change-class.initforms
.4 ()
372 (change-class.initforms
.2 () change-class.initforms
.4 (:foo
:fez
)
375 ;; Value is retained.
376 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.3 ()
378 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.3 (:foo
:fez
)
380 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.4 ()
382 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.4 (:foo
:fez
)
385 ;; Test for FORWARD-REFERENCED-CLASS
387 (defclass change-class.forward-referenced
.1 () ())
388 ;; CHANGE-CLASS.FORWARD-REFERENCED.2 is only needed to create the
389 ;; FORWARD-REFERENCED-CLASS CHANGE-CLASS.FORWARD-REFERENCED.3.
390 (defclass change-class.forward-referenced
.2 (change-class.forward-referenced
.3) ())
392 (with-test (:name
(change-class sb-pcl
:forward-referenced-class
))
394 #'change-class-test-case
395 '(;; Changing instances of "ordinary classes" to classes which are
396 ;; instances of FORWARD-REFERENCED-CLASS is not allowed.
397 (change-class.forward-referenced
.1 () change-class.forward-referenced
.3 ()
400 ;; Changing instances of FORWARD-REFERENCED-CLASS into
401 ;; non-CLASSes and in particular non-CLASS metaobjects is not
403 ((:class change-class.forward-referenced
.3) () change-class.forward-referenced
.1 ()
405 ((:class change-class.forward-referenced
.3) () generic-function
()
407 ((:class change-class.forward-referenced
.3) () method
()
409 ((:class change-class.forward-referenced
.3) () slot-definition
()
412 ;; Changing instances of FORWARD-REFERENCED-CLASS into CLASS is
413 ;; allowed but destructive. Therefore has to be final test case.
414 ((:class change-class.forward-referenced
.3) () standard-class
()
417 ;; Test for FUNCALLABLE-STANDARD-CLASS
419 (defclass change-class.funcallable
.1 () ())
420 (defclass change-class.funcallable
.2 () ()
421 (:metaclass sb-mop
:funcallable-standard-class
))
422 (defclass change-class.funcallable
.3 () ()
423 (:metaclass sb-mop
:funcallable-standard-class
))
425 (with-test (:name
(change-class sb-mop
:funcallable-standard-class
))
427 #'change-class-test-case
428 '(;; Cannot change STANDARD-OBJECT into FUNCALLABLE-STANDARD-OBJECT
430 (change-class.funcallable
.1 () change-class.funcallable
.2 ()
432 (change-class.funcallable
.2 () change-class.funcallable
.1 ()
434 ;; FUNCALLABLE-STANDARD-OBJECTs should work.
435 (change-class.funcallable
.2 () change-class.funcallable
.2 ()
437 (change-class.funcallable
.2 () change-class.funcallable
.3 ()
440 ;;; Until Pierre Mai's patch (sbcl-devel 2002-06-18, merged in
441 ;;; sbcl-0.7.4.39) the :MOST-SPECIFIC-LAST option had no effect.
442 (defgeneric bug180
(x)
443 (:method-combination list
:most-specific-last
))
444 (defmethod bug180 list
((x number
))
446 (defmethod bug180 list
((x fixnum
))
448 (assert (equal (bug180 14) '(number fixnum
)))
450 ;;; printing a structure class should not loop indefinitely (or cause
451 ;;; a stack overflow):
452 (defclass test-printing-structure-class
()
453 ((slot :initarg
:slot
))
454 (:metaclass structure-class
))
455 (print (make-instance 'test-printing-structure-class
:slot
2))
457 ;;; structure-classes should behave nicely when subclassed
458 (defclass super-structure
()
459 ((a :initarg
:a
:accessor a-accessor
)
460 (b :initform
2 :reader b-reader
))
461 (:metaclass structure-class
))
462 (defclass sub-structure
(super-structure)
463 ((c :initarg
:c
:writer c-writer
:accessor c-accessor
))
464 (:metaclass structure-class
))
465 (let ((foo (make-instance 'sub-structure
:a
1 :c
3)))
466 (assert (= (a-accessor foo
) 1))
467 (assert (= (b-reader foo
) 2))
468 (assert (= (c-accessor foo
) 3))
469 (setf (a-accessor foo
) 4)
471 (assert (= (a-accessor foo
) 4))
472 (assert (= (c-accessor foo
) 5)))
474 ;;; At least as of sbcl-0.7.4, PCL has code to support a special
475 ;;; encoding of effective method functions for slot accessors as
476 ;;; FIXNUMs. Given this special casing, it'd be easy for slot accessor
477 ;;; functions to get broken in special ways even though ordinary
478 ;;; generic functions work. As of sbcl-0.7.4 we didn't have any tests
479 ;;; for that possibility. Now we have a few tests:
481 ((fin :reader ffin
:writer ffin
!)
482 (tail :reader ftail
:writer ftail
!)))
483 (defvar *fish
* (make-instance 'fish
))
484 (ffin! 'triangular-fin
*fish
*)
485 (defclass cod
(fish) ())
486 (defvar *cod
* (make-instance 'cod
))
487 (defparameter *clos-dispatch-side-fx
* (make-array 0 :fill-pointer
0))
488 (defmethod ffin! (new-fin (cod cod
))
489 (format t
"~&about to set ~S fin to ~S~%" cod new-fin
)
490 (vector-push-extend '(cod) *clos-dispatch-side-fx
*)
493 (format t
"~&done setting ~S fin to ~S~%" cod new-fin
)))
494 (defmethod ffin! :before
(new-fin (cod cod
))
495 (vector-push-extend '(:before cod
) *clos-dispatch-side-fx
*)
496 (format t
"~&exploring the CLOS dispatch zoo with COD fins~%"))
497 (ffin! 'almost-triang-fin
*cod
*)
498 (assert (eq (ffin *cod
*) 'almost-triang-fin
))
499 (assert (equalp #((:before cod
) (cod)) *clos-dispatch-side-fx
*))
501 ;;; Until sbcl-0.7.6.21, the long form of DEFINE-METHOD-COMBINATION
502 ;;; ignored its options; Gerd Moellmann found and fixed the problem
503 ;;; for cmucl (cmucl-imp 2002-06-18).
504 (define-method-combination test-mc
(x)
505 ;; X above being a method-group-specifier
506 ((primary () :required t
))
507 `(call-method ,(first primary
)))
510 (:method-combination test-mc
1))
515 ;;; Until sbcl-0.7.7.20, some conditions weren't being signalled, and
516 ;;; some others were of the wrong type:
517 (macrolet ((assert-program-error (form)
518 `(multiple-value-bind (value error
)
519 (ignore-errors ,form
)
520 (unless (and (null value
) (typep error
'program-error
))
521 (error "~S failed: ~S, ~S" ',form value error
)))))
522 (assert-program-error (defclass foo001
() (a b a
)))
523 (assert-program-error (defclass foo002
()
525 (:default-initargs x
'a x
'b
)))
526 (assert-program-error (defclass foo003
()
527 ((a :allocation
:class
:allocation
:class
))))
528 (assert-program-error (defclass foo004
()
530 ;; and some more, found by Wolfhard Buss and fixed for cmucl by Gerd
531 ;; Moellmann in sbcl-0.7.8.x:
532 (assert-program-error (progn
533 (defmethod odd-key-args-checking (&key
(key 42)) key
)
534 (odd-key-args-checking 3)))
535 (assert (= (odd-key-args-checking) 42))
536 (assert (eq (odd-key-args-checking :key t
) t
))
537 ;; yet some more, fixed in sbcl-0.7.9.xx
538 (assert-program-error (defclass foo005
()
539 (:metaclass sb-pcl
::funcallable-standard-class
)
541 (assert-program-error (defclass foo006
()
542 ((a :reader
(setf a
)))))
543 (assert-program-error (defclass foo007
()
545 (assert-program-error (defclass foo008
()
547 (:default-initargs
:a
1)
548 (:default-initargs
:a
2)))
549 ;; and also BUG 47d, fixed in sbcl-0.8alpha.0.26
550 (assert-program-error (defgeneric if
(x)))
551 ;; DEFCLASS should detect an error if slot names aren't suitable as
553 (assert-program-error (defclass foo009
()
555 (assert-program-error (defclass foo010
()
556 (("a" :initarg
:a
))))
557 (assert-program-error (defclass foo011
()
558 ((#1a
() :initarg
:a
))))
559 (assert-program-error (defclass foo012
()
561 (assert-program-error (defclass foo013
() ("a")))
562 ;; specialized lambda lists have certain restrictions on ordering,
563 ;; repeating keywords, and the like:
564 (assert-program-error (defmethod foo014 ((foo t
) &rest
) nil
))
565 (assert-program-error (defmethod foo015 ((foo t
) &rest x y
) nil
))
566 (assert-program-error (defmethod foo016 ((foo t
) &allow-other-keys
) nil
))
567 (assert-program-error (defmethod foo017 ((foo t
)
568 &optional x
&optional y
) nil
))
569 (assert-program-error (defmethod foo018 ((foo t
) &rest x
&rest y
) nil
))
570 (assert-program-error (defmethod foo019 ((foo t
) &rest x
&optional y
) nil
))
571 (assert-program-error (defmethod foo020 ((foo t
) &key x
&optional y
) nil
))
572 (assert-program-error (defmethod foo021 ((foo t
) &key x
&rest y
) nil
)))
574 ;;; DOCUMENTATION's argument-precedence-order wasn't being faithfully
575 ;;; preserved through the bootstrap process until sbcl-0.7.8.39.
576 ;;; (thanks to Gerd Moellmann)
577 (with-test (:name
:documentation-argument-precedence-order
)
581 (let ((answer (documentation 'foo022
'function
)))
582 (assert (stringp answer
))
583 (defmethod documentation ((x (eql 'foo022
)) y
) "WRONG")
584 (assert (string= (documentation 'foo022
'function
) answer
))))
586 ;;; only certain declarations are permitted in DEFGENERIC
587 (macrolet ((assert-program-error (form)
588 `(multiple-value-bind (value error
)
589 (ignore-errors ,form
)
590 (assert (null value
))
591 (assert (typep error
'program-error
)))))
592 (assert-program-error (defgeneric bogus-declaration
(x)
593 (declare (special y
))))
594 (assert-program-error (defgeneric bogus-declaration2
(x)
595 (declare (notinline concatenate
)))))
596 ;;; CALL-NEXT-METHOD should call NO-NEXT-METHOD if there is no next
598 (defmethod no-next-method-test ((x integer
)) (call-next-method))
599 (assert (null (ignore-errors (no-next-method-test 1))))
600 (defmethod no-next-method ((g (eql #'no-next-method-test
)) m
&rest args
)
602 (assert (eq (no-next-method-test 1) 'success
))
603 (assert (null (ignore-errors (no-next-method-test 'foo
))))
605 ;;; regression test for bug 176, following a fix that seems
606 ;;; simultaneously to fix 140 while not exposing 176 (by Gerd
607 ;;; Moellmann, merged in sbcl-0.7.9.12).
609 (let ((lastname (intern (format nil
"C176-~D" (1- i
))))
610 (name (intern (format nil
"C176-~D" i
))))
611 (eval `(defclass ,name
612 (,@(if (= i
0) nil
(list lastname
)))
614 (eval `(defmethod initialize-instance :after
((x ,name
) &rest any
)
615 (declare (ignore any
))))))
616 (defclass b176
() (aslot-176))
617 (defclass c176-0
(b176) ())
618 (assert (= 1 (setf (slot-value (make-instance 'c176-9
) 'aslot-176
) 1)))
620 ;;; DEFINE-METHOD-COMBINATION was over-eager at checking for duplicate
622 (define-method-combination dmc-test-mc
(&optional
(order :most-specific-first
))
624 (primary (dmc-test-mc) :order order
:required t
))
625 (let ((form (if (rest primary
)
626 `(and ,@(mapcar #'(lambda (method)
627 `(call-method ,method
))
629 `(call-method ,(first primary
)))))
631 `(call-method ,(first around
)
633 (make-method ,form
)))
636 (defgeneric dmc-test-mc
(&key k
)
637 (:method-combination dmc-test-mc
))
639 (defmethod dmc-test-mc dmc-test-mc
(&key k
)
643 ;;; While I'm at it, DEFINE-METHOD-COMBINATION is defined to return
644 ;;; the NAME argument, not some random method object. So:
645 (assert (eq (define-method-combination dmc-test-return-foo
)
646 'dmc-test-return-foo
))
647 (assert (eq (define-method-combination dmc-test-return-bar
:operator and
)
648 'dmc-test-return-bar
))
649 (assert (eq (define-method-combination dmc-test-return
650 (&optional
(order :most-specific-first
))
652 (primary (dmc-test-return) :order order
:required t
))
653 (let ((form (if (rest primary
)
654 `(and ,@(mapcar #'(lambda (method)
655 `(call-method ,method
))
657 `(call-method ,(first primary
)))))
659 `(call-method ,(first around
)
661 (make-method ,form
)))
665 ;;; DEFINE-METHOD-COMBINATION should, according to the description in 7.7,
666 ;;; allow you to do everything in the body forms yourself if you specify
667 ;;; exactly one method group whose qualifier-pattern is *
669 ;;; The specific language is:
670 ;;; "The use of method group specifiers provides a convenient syntax to select
671 ;;; methods, to divide them among the possible roles, and to perform the
672 ;;; necessary error checking. It is possible to perform further filtering of
673 ;;; methods in the body forms by using normal list-processing operations and
674 ;;; the functions method-qualifiers and invalid-method-error. It is permissible
675 ;;; to use setq on the variables named in the method group specifiers and to
676 ;;; bind additional variables. It is also possible to bypass the method group
677 ;;; specifier mechanism and do everything in the body forms. This is
678 ;;; accomplished by writing a single method group with * as its only
679 ;;; qualifier-pattern; the variable is then bound to a list of all of the
680 ;;; applicable methods, in most-specific-first order."
681 (define-method-combination wam-test-method-combination-a
()
683 (do ((methods all-methods
(rest methods
))
687 (let ((primary (nreverse primary
))
688 (around (nreverse around
)))
690 (let ((form (if (rest primary
)
691 `(call-method ,(first primary
) ,(rest primary
))
692 `(call-method ,(first primary
)))))
694 `(call-method ,(first around
) (,@(rest around
)
695 (make-method ,form
)))
697 `(make-method (error "No primary methods")))))
698 (let* ((method (first methods
))
699 (qualifier (first (method-qualifiers method
))))
701 ((equal :around qualifier
)
702 (push method around
))
704 (push method primary
))))))
706 (defgeneric wam-test-mc-a
(val)
707 (:method-combination wam-test-method-combination-a
))
708 (assert-error (wam-test-mc-a 13))
709 (defmethod wam-test-mc-a ((val number
))
710 (+ val
(if (next-method-p) (call-next-method) 0)))
711 (assert (= (wam-test-mc-a 13) 13))
712 (defmethod wam-test-mc-a :around
((val number
))
713 (+ val
(if (next-method-p) (call-next-method) 0)))
714 (assert (= (wam-test-mc-a 13) 26))
716 ;;; DEFINE-METHOD-COMBINATION
717 ;;; When two methods are in the same method group and have the same
718 ;;; specializers, their sort order within the group may be ambiguous. Therefore,
719 ;;; we should throw an error when we have two methods in the same group with
720 ;;; the same specializers /as long as/ we have more than one method group
721 ;;; or our single method group qualifier-pattern is not *. This resolves the
722 ;;; apparent conflict with the above 'It is also possible to bypass' language.
724 ;;; The language specifying this behavior is:
725 ;;; "Note that two methods with identical specializers, but with different
726 ;;; qualifiers, are not ordered by the algorithm described in Step 2 of the
727 ;;; method selection and combination process described in Section 7.6.6
728 ;;; (Method Selection and Combination). Normally the two methods play different
729 ;;; roles in the effective method because they have different qualifiers, and
730 ;;; no matter how they are ordered in the result of Step 2, the effective
731 ;;; method is the same. If the two methods play the same role and their order
732 ;;; matters, an error is signaled. This happens as part of the qualifier
733 ;;; pattern matching in define-method-combination."
735 ;;; Note that the spec pretty much equates 'method group' and 'role'.
736 ;; First we ensure that it fails correctly when there is more than one
738 (define-method-combination wam-test-method-combination-b
()
740 (primary * :required t
))
741 (let ((form (if (rest primary
)
742 `(call-method ,(first primary
) ,(rest primary
))
743 `(call-method ,(first primary
)))))
745 `(call-method ,(first around
) (,@(rest around
)
746 (make-method ,form
)))
749 (defgeneric wam-test-mc-b
(val)
750 (:method-combination wam-test-method-combination-b
))
751 (defmethod wam-test-mc-b ((val number
))
752 (+ val
(if (next-method-p) (call-next-method) 0)))
753 (assert (= (wam-test-mc-b 13) 13))
754 (defmethod wam-test-mc-b :around
((val number
))
755 (+ val
(if (next-method-p) (call-next-method) 0)))
756 (assert (= (wam-test-mc-b 13) 26))
757 (defmethod wam-test-mc-b :somethingelse
((val number
))
758 (+ val
(if (next-method-p) (call-next-method) 0)))
759 (assert-error (wam-test-mc-b 13))
761 ;;; now, ensure that it fails with a single group with a qualifier-pattern
763 (define-method-combination wam-test-method-combination-c
()
764 ((methods listp
:required t
))
766 `(call-method ,(first methods
) ,(rest methods
))
767 `(call-method ,(first methods
))))
769 (defgeneric wam-test-mc-c
(val)
770 (:method-combination wam-test-method-combination-c
))
771 (assert-error (wam-test-mc-c 13))
772 (defmethod wam-test-mc-c :foo
((val number
))
773 (+ val
(if (next-method-p) (call-next-method) 0)))
774 (assert (= (wam-test-mc-c 13) 13))
775 (defmethod wam-test-mc-c :bar
((val number
))
776 (+ val
(if (next-method-p) (call-next-method) 0)))
777 (assert-error (wam-test-mc-c 13))
779 ;;; DEFMETHOD should signal an ERROR if an incompatible lambda list is
781 (defmethod incompatible-ll-test-1 (x) x
)
782 (assert-error (defmethod incompatible-ll-test-1 (x y
) y
))
783 (assert-error (defmethod incompatible-ll-test-1 (x &rest y
) y
))
784 ;;; Sneakily using a bit of MOPness to check some consistency
786 (sb-pcl:generic-function-methods
#'incompatible-ll-test-1
)) 1))
788 (defmethod incompatible-ll-test-2 (x &key bar
) bar
)
789 (assert-error (defmethod incompatible-ll-test-2 (x) x
))
790 (defmethod incompatible-ll-test-2 (x &rest y
) y
)
792 (sb-pcl:generic-function-methods
#'incompatible-ll-test-2
)) 1))
793 (defmethod incompatible-ll-test-2 ((x integer
) &key bar
) bar
)
795 (sb-pcl:generic-function-methods
#'incompatible-ll-test-2
)) 2))
797 ;;; Per Christophe, this is an illegal method call because of 7.6.5
798 (assert-error (incompatible-ll-test-2 t
1 2))
800 (assert (eq (incompatible-ll-test-2 1 :bar
'yes
) 'yes
))
802 (defmethod incompatible-ll-test-3 ((x integer
)) x
)
803 (remove-method #'incompatible-ll-test-3
804 (find-method #'incompatible-ll-test-3
806 (list (find-class 'integer
))))
807 (assert-error (defmethod incompatible-ll-test-3 (x y
) (list x y
)))
810 ;;; Attempting to instantiate classes with forward references in their
811 ;;; CPL should signal errors (FIXME: of what type?)
812 (defclass never-finished-class
(this-one-unfinished-too) ())
813 (multiple-value-bind (result error
)
814 (ignore-errors (make-instance 'never-finished-class
))
815 (assert (null result
))
816 (assert (typep error
'error
)))
817 (multiple-value-bind (result error
)
818 (ignore-errors (make-instance 'this-one-unfinished-too
))
819 (assert (null result
))
820 (assert (typep error
'error
)))
822 ;;; Classes with :ALLOCATION :CLASS slots should be subclassable (and
823 ;;; weren't for a while in sbcl-0.7.9.xx)
824 (defclass superclass-with-slot
()
825 ((a :allocation
:class
)))
826 (defclass subclass-for-class-allocation
(superclass-with-slot) ())
827 (make-instance 'subclass-for-class-allocation
)
829 ;;; bug #136: CALL-NEXT-METHOD was being a little too lexical,
830 ;;; resulting in failure in the following:
831 (defmethod call-next-method-lexical-args ((x integer
))
833 (defmethod call-next-method-lexical-args :around
((x integer
))
836 (assert (= (call-next-method-lexical-args 3) 3))
838 ;;; DEFINE-METHOD-COMBINATION with arguments was hopelessly broken
840 (defvar *d-m-c-args-test
* nil
)
841 (define-method-combination progn-with-lock
()
845 (progn (lock (object-lock ,object
))
846 ,@(mapcar #'(lambda (method)
847 `(call-method ,method
))
849 (unlock (object-lock ,object
))))
850 (defun object-lock (obj)
851 (push "object-lock" *d-m-c-args-test
*)
854 (push "unlock" *d-m-c-args-test
*)
857 (push "lock" *d-m-c-args-test
*)
859 (defgeneric d-m-c-args-test
(x)
860 (:method-combination progn-with-lock
))
861 (defmethod d-m-c-args-test ((x symbol
))
862 (push "primary" *d-m-c-args-test
*))
863 (defmethod d-m-c-args-test ((x number
))
865 (assert (equal (d-m-c-args-test t
) '("primary" "lock" "object-lock")))
866 (assert (equal *d-m-c-args-test
*
867 '("unlock" "object-lock" "primary" "lock" "object-lock")))
868 (setf *d-m-c-args-test
* nil
)
869 (ignore-errors (d-m-c-args-test 1))
870 (assert (equal *d-m-c-args-test
*
871 '("unlock" "object-lock" "lock" "object-lock")))
873 ;;; The walker (on which DEFMETHOD depended) didn't know how to handle
874 ;;; SYMBOL-MACROLET properly. In fact, as of sbcl-0.7.10.20 it still
875 ;;; doesn't, but it does well enough to compile the following without
876 ;;; error (the problems remain in asking for a complete macroexpansion
877 ;;; of an arbitrary form).
878 (symbol-macrolet ((x 1))
879 (defmethod bug222 (z)
880 (macrolet ((frob (form) `(progn ,form
,x
)))
882 (assert (= (bug222 t
) 1))
884 ;;; also, a test case to guard against bogus environment hacking:
886 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
888 ;;; this should at the least compile:
890 (defmethod bug222-b (z stream
)
891 (macrolet ((frob (form) `(progn ,form
,bug222-b
)))
892 (frob (format stream
"~D~%" bug222-b
)))))
893 ;;; and it would be nice (though not specified by ANSI) if the answer
895 (let ((x (make-string-output-stream)))
896 (let ((value (bug222-b t x
)))
897 ;; not specified by ANSI
898 #+#.
(cl:if
(cl:eq sb-ext
:*evaluator-mode
* :compile
) '(and) '(or))
899 (assert (= value
3)))
901 (assert (char= (char (get-output-stream-string x
) 0) #\
1)))
903 ;;; REINITIALIZE-INSTANCE, in the ctor optimization, wasn't checking
904 ;;; for invalid initargs where it should:
905 (defclass class234
() ())
906 (defclass subclass234
(class234) ())
909 (reinitialize-instance (make-instance 'class234
) :dummy
0))
911 (reinitialize-instance (make-instance 'subclass234
) :dummy
0))
912 (assert-error (bug-234) program-error
)
913 (defmethod shared-initialize :after
((i class234
) slots
&key dummy
)
915 (assert (typep (subbug-234) 'subclass234
))
917 ;; once for MAKE-INSTANCE, once for REINITIALIZE-INSTANCE
920 ;;; also, some combinations of MAKE-INSTANCE and subclassing missed
921 ;;; new methods (Gerd Moellmann sbcl-devel 2002-12-29):
922 (defclass class234-b1
() ())
923 (defclass class234-b2
(class234-b1) ())
924 (defvar *bug234-b
* 0)
926 (make-instance 'class234-b2
))
929 (assert (= *bug234-b
* 0))
930 (defmethod initialize-instance :before
((x class234-b1
) &rest args
)
931 (declare (ignore args
))
934 (assert (= *bug234-b
* 1))
936 ;;; we should be able to make classes with uninterned names:
937 (defclass #:class-with-uninterned-name
() ())
939 ;;; SLOT-MISSING should be called when there are missing slots.
940 (defclass class-with-all-slots-missing
() ())
941 (defmethod slot-missing (class (o class-with-all-slots-missing
)
944 (declare (ignore new-value
))
946 (assert (eq (slot-value (make-instance 'class-with-all-slots-missing
) 'foo
)
948 (assert (eq (funcall (lambda (x) (slot-value x
'bar
))
949 (make-instance 'class-with-all-slots-missing
))
951 (macrolet ((try (which)
952 `(assert (eq ((lambda (x)
953 (declare (,which sb-pcl
::set-slot-value
))
954 (setf (slot-value x
'b
) 'baz
))
955 (make-instance 'class-with-all-slots-missing
))
956 ;; SLOT-MISSING's value is specified to be ignored; we
962 ;;; we should be able to specialize on anything that names a class.
963 (defclass name-for-class
() ())
964 (defmethod something-that-specializes ((x name-for-class
)) 1)
965 (setf (find-class 'other-name-for-class
) (find-class 'name-for-class
))
966 (defmethod something-that-specializes ((x other-name-for-class
)) 2)
967 (assert (= (something-that-specializes (make-instance 'name-for-class
)) 2))
968 (assert (= (something-that-specializes (make-instance 'other-name-for-class
))
971 ;;; more forward referenced classes stuff
972 (defclass frc-1
(frc-2) ())
973 (assert (subtypep 'frc-1
(find-class 'frc-2
)))
974 (assert (subtypep (find-class 'frc-1
) 'frc-2
))
975 (assert (not (subtypep (find-class 'frc-2
) 'frc-1
)))
976 (defclass frc-2
(frc-3) ((a :initarg
:a
)))
977 (assert (subtypep 'frc-1
(find-class 'frc-3
)))
978 (defclass frc-3
() ())
979 (assert (typep (make-instance 'frc-1
:a
2) (find-class 'frc-1
)))
980 (assert (typep (make-instance 'frc-2
:a
3) (find-class 'frc-2
)))
982 ;;; check that we can define classes with two slots of different names
983 ;;; (even if it STYLE-WARNs).
984 (defclass odd-name-class
()
985 ((name :initarg
:name
)
986 (cl-user::name
:initarg
:name2
)))
987 (let ((x (make-instance 'odd-name-class
:name
1 :name2
2)))
988 (assert (= (slot-value x
'name
) 1))
989 (assert (= (slot-value x
'cl-user
::name
) 2)))
991 ;;; ALLOCATE-INSTANCE should work on structures, even if defined by
992 ;;; DEFSTRUCT (and not DEFCLASS :METACLASS STRUCTURE-CLASS).
993 (defstruct allocatable-structure a
)
994 (assert (typep (allocate-instance (find-class 'allocatable-structure
))
995 'allocatable-structure
))
997 ;;; Bug found by Paul Dietz when devising CPL tests: somewhat
998 ;;; amazingly, calls to CPL would work a couple of times, and then
999 ;;; start returning NIL. A fix was found (relating to the
1000 ;;; applicability of constant-dfun optimization) by Gerd Moellmann.
1002 (:method-combination list
)
1003 (:method list
((x broadcast-stream
)) 'broadcast-stream
)
1004 (:method list
((x integer
)) 'integer
)
1005 (:method list
((x number
)) 'number
)
1006 (:method list
((x stream
)) 'stream
)
1007 (:method list
((x structure-object
)) 'structure-object
))
1008 (assert (equal (cpl 0) '(integer number
)))
1009 (assert (equal (cpl 0) '(integer number
)))
1010 (assert (equal (cpl 0) '(integer number
)))
1011 (assert (equal (cpl 0) '(integer number
)))
1012 (assert (equal (cpl 0) '(integer number
)))
1013 (assert (equal (cpl (make-broadcast-stream))
1014 '(broadcast-stream stream structure-object
)))
1015 (assert (equal (cpl (make-broadcast-stream))
1016 '(broadcast-stream stream structure-object
)))
1017 (assert (equal (cpl (make-broadcast-stream))
1018 '(broadcast-stream stream structure-object
)))
1020 ;;; Bug in CALL-NEXT-METHOD: assignment to the method's formal
1021 ;;; parameters shouldn't affect the arguments to the next method for a
1022 ;;; no-argument call to CALL-NEXT-METHOD
1023 (defgeneric cnm-assignment
(x)
1025 (:method
((x integer
)) (setq x
3)
1026 (list x
(call-next-method) (call-next-method x
))))
1027 (assert (equal (cnm-assignment 1) '(3 1 3)))
1029 ;;; Bug reported by Istvan Marko 2003-07-09
1030 (let ((class-name (gentemp)))
1031 (loop for i from
1 to
9
1032 for slot-name
= (intern (format nil
"X~D" i
))
1033 for initarg-name
= (intern (format nil
"X~D" i
) :keyword
)
1034 collect
`(,slot-name
:initarg
,initarg-name
) into slot-descs
1035 append
`(,initarg-name
(list 0)) into default-initargs
1036 finally
(eval `(defclass ,class-name
()
1038 (:default-initargs
,@default-initargs
))))
1039 (let ((f (compile nil
`(lambda () (make-instance ',class-name
)))))
1040 (assert (typep (funcall f
) class-name
))))
1042 ;;; bug 262: DEFMETHOD failed on a generic function without a lambda
1044 (ensure-generic-function 'bug262
)
1045 (defmethod bug262 (x y
)
1047 (assert (equal (bug262 1 2) '(1 2)))
1049 ;;; salex on #lisp 2003-10-13 reported that type declarations inside
1050 ;;; WITH-SLOTS are too hairy to be checked
1051 (defun ensure-no-notes (form)
1052 (handler-case (compile nil
`(lambda () ,form
))
1053 (sb-ext:compiler-note
(c)
1054 ;; FIXME: it would be better to check specifically for the "type
1055 ;; is too hairy" note
1058 (ensure-no-notes '(with-slots (a) *x
*
1059 (declare (integer a
))
1061 (ensure-no-notes '(with-slots (a) *x
*
1062 (declare (integer a
))
1063 (declare (notinline slot-value
))
1066 ;;; from CLHS 7.6.5.1
1067 (defclass character-class
() ((char :initarg
:char
)))
1068 (defclass picture-class
() ((glyph :initarg
:glyph
)))
1069 (defclass character-picture-class
(character-class picture-class
) ())
1071 (defmethod width ((c character-class
) &key font
) font
)
1072 (defmethod width ((p picture-class
) &key pixel-size
) pixel-size
)
1075 (width (make-instance 'character-class
:char
#\Q
)
1076 :font
'baskerville
:pixel-size
10)
1079 (width (make-instance 'picture-class
:glyph
#\Q
)
1080 :font
'baskerville
:pixel-size
10)
1082 (assert (eq (width (make-instance 'character-picture-class
:char
#\Q
)
1083 :font
'baskerville
:pixel-size
10)
1086 ;;; class redefinition shouldn't give any warnings, in the usual case
1087 (defclass about-to-be-redefined
() ((some-slot :accessor some-slot
)))
1088 (handler-bind ((warning #'error
))
1089 (defclass about-to-be-redefined
() ((some-slot :accessor some-slot
))))
1091 ;;; attempts to add accessorish methods to generic functions with more
1092 ;;; complex lambda lists should fail
1093 (defgeneric accessoroid
(object &key
&allow-other-keys
))
1095 (defclass accessoroid-class
() ((slot :accessor accessoroid
)))
1098 ;;; reported by Bruno Haible sbcl-devel 2004-04-15
1099 (defclass shared-slot-and-redefinition
()
1100 ((size :initarg
:size
:initform
1 :allocation
:class
)))
1101 (let ((i (make-instance 'shared-slot-and-redefinition
)))
1102 (defclass shared-slot-and-redefinition
()
1103 ((size :initarg
:size
:initform
2 :allocation
:class
)))
1104 (assert (= (slot-value i
'size
) 1)))
1106 ;;; reported by Bruno Haible sbcl-devel 2004-04-15
1107 (defclass superclass-born-to-be-obsoleted
() (a))
1108 (defclass subclass-born-to-be-obsoleted
(superclass-born-to-be-obsoleted) ())
1109 (defparameter *born-to-be-obsoleted
*
1110 (make-instance 'subclass-born-to-be-obsoleted
))
1111 (defparameter *born-to-be-obsoleted-obsoleted
* nil
)
1112 (defmethod update-instance-for-redefined-class
1113 ((o subclass-born-to-be-obsoleted
) a d pl
&key
)
1114 (setf *born-to-be-obsoleted-obsoleted
* t
))
1115 (make-instances-obsolete 'superclass-born-to-be-obsoleted
)
1116 (slot-boundp *born-to-be-obsoleted
* 'a
)
1117 (assert *born-to-be-obsoleted-obsoleted
*)
1119 ;;; additional test suggested by Bruno Haible sbcl-devel 2004-04-21
1120 (defclass super-super-obsoleted
() (a))
1121 (defclass super-obsoleted-1
(super-super-obsoleted) ())
1122 (defclass super-obsoleted-2
(super-super-obsoleted) ())
1123 (defclass obsoleted
(super-obsoleted-1 super-obsoleted-2
) ())
1124 (defparameter *obsoleted
* (make-instance 'obsoleted
))
1125 (defparameter *obsoleted-counter
* 0)
1126 (defmethod update-instance-for-redefined-class ((o obsoleted
) a d pl
&key
)
1127 (incf *obsoleted-counter
*))
1128 (make-instances-obsolete 'super-super-obsoleted
)
1129 (slot-boundp *obsoleted
* 'a
)
1130 (assert (= *obsoleted-counter
* 1))
1132 ;;; yet another MAKE-INSTANCES-OBSOLETE test, this time from Nikodemus
1133 ;;; Siivola. Not all methods for accessing slots are created equal...
1134 (defclass yet-another-obsoletion-super
() ((obs :accessor obs-of
:initform
0)))
1135 (defclass yet-another-obsoletion-sub
(yet-another-obsoletion-super) ())
1136 (defmethod shared-initialize :after
((i yet-another-obsoletion-super
)
1140 (defvar *yao-super
* (make-instance 'yet-another-obsoletion-super
))
1141 (defvar *yao-sub
* (make-instance 'yet-another-obsoletion-sub
))
1143 (assert (= (obs-of *yao-super
*) 1))
1144 (assert (= (obs-of *yao-sub
*) 1))
1145 (make-instances-obsolete 'yet-another-obsoletion-super
)
1146 (assert (= (obs-of *yao-sub
*) 2))
1147 (assert (= (obs-of *yao-super
*) 2))
1148 (make-instances-obsolete 'yet-another-obsoletion-super
)
1149 (assert (= (obs-of *yao-super
*) 3))
1150 (assert (= (obs-of *yao-sub
*) 3))
1151 (assert (= (slot-value *yao-super
* 'obs
) 3))
1152 (assert (= (slot-value *yao-sub
* 'obs
) 3))
1154 ;;; one more MIO test: variable slot names
1155 (defclass mio
() ((x :initform
42)))
1156 (defvar *mio-slot
* 'x
)
1157 (defparameter *mio-counter
* 0)
1158 (defmethod update-instance-for-redefined-class ((instance mio
) new old plist
&key
)
1159 (incf *mio-counter
*))
1161 (let ((x (make-instance 'mio
)))
1162 (make-instances-obsolete 'mio
)
1163 (slot-value x
*mio-slot
*))
1165 (let ((x (make-instance 'mio
)))
1166 (make-instances-obsolete 'mio
)
1167 (setf (slot-value x
*mio-slot
*) 13))
1169 (let ((x (make-instance 'mio
)))
1170 (make-instances-obsolete 'mio
)
1171 (slot-boundp x
*mio-slot
*))
1173 (let ((x (make-instance 'mio
)))
1174 (make-instances-obsolete 'mio
)
1175 (slot-makunbound x
*mio-slot
*))
1177 (assert (= 4 *mio-counter
*))
1179 ;;; :class -> :instance slot allocation transfers of inherited slots,
1180 ;;; reported by Bruno Haible
1181 (with-test (:name
(defclass :redefinition-class-
>instance-allocation
))
1183 (defclass super-with-magic-slot
()
1184 ((magic :initarg
:size
:initform
1 :allocation
:class
)))
1185 (defclass sub-of-super-with-magic-slot
(super-with-magic-slot) ())
1186 (setq i
(make-instance 'sub-of-super-with-magic-slot
))
1187 (defclass super-with-magic-slot
()
1188 ((magic :initarg
:size
:initform
2)))
1189 (assert (= 1 (slot-value i
'magic
)))))
1191 ;;; MAKE-INSTANCES-OBSOLETE return values
1192 (with-test (:name
(make-instances-obsolete :return-values
) )
1193 (defclass one-more-to-obsolete
() ())
1194 (assert (eq 'one-more-to-obsolete
1195 (make-instances-obsolete 'one-more-to-obsolete
)))
1196 (assert (eq (find-class 'one-more-to-obsolete
)
1197 (make-instances-obsolete (find-class 'one-more-to-obsolete
)))))
1199 ;;; Sensible error instead of a BUG. Reported by Thomas Burdick.
1200 (with-test (:name
(defclass :slot-with-duplicate-accessors
))
1201 (assert-error (defclass slot-with-duplicate-accessors
()
1202 ((slot :writer get-slot
:reader get-slot
)))
1203 (and error
(not sb-int
:bug
))))
1205 ;;; BUG 321: errors in parsing DEFINE-METHOD-COMBINATION arguments
1208 (define-method-combination w-args
()
1210 (:arguments arg1 arg2
&aux
(extra :extra
))
1211 (declare (ignore arg1 arg2 extra
))
1212 `(progn ,@(mapcar (lambda (method) `(call-method ,method
)) method-list
)))
1213 (defgeneric mc-test-w-args
(p1 p2 s
)
1214 (:method-combination w-args
)
1215 (:method
((p1 number
) (p2 t
) s
)
1216 (vector-push-extend (list 'number p1 p2
) s
))
1217 (:method
((p1 string
) (p2 t
) s
)
1218 (vector-push-extend (list 'string p1 p2
) s
))
1219 (:method
((p1 t
) (p2 t
) s
) (vector-push-extend (list t p1 p2
) s
)))
1220 (let ((v (make-array 0 :adjustable t
:fill-pointer t
)))
1221 (assert (= (mc-test-w-args 1 2 v
) 1))
1222 (assert (equal (aref v
0) '(number 1 2)))
1223 (assert (equal (aref v
1) '(t 1 2))))
1225 ;;; BUG 276: declarations and mutation.
1226 (defmethod fee ((x fixnum
))
1229 (assert (= (fee 1) 1/2))
1230 (defmethod fum ((x fixnum
))
1233 (assert (= (fum 3) 3/2))
1234 (defmethod fii ((x fixnum
))
1235 (declare (special x
))
1238 (assert (= (fii 1) 1/2))
1240 (defmethod faa ((*faa
* string-stream
))
1241 (setq *faa
* (make-broadcast-stream *faa
*))
1242 (write-line "Break, you sucker!" *faa
*)
1244 (assert (eq 'ok
(faa (make-string-output-stream))))
1245 (defmethod fex ((x fixnum
) (y fixnum
))
1246 (multiple-value-setq (x y
) (values (/ x y
) (/ y x
)))
1248 (assert (equal (fex 5 3) '(5/3 3/5)))
1250 ;;; Bug reported by Zach Beane; incorrect return of (function
1251 ;;; ',fun-name) in defgeneric
1253 (typep (funcall (compile nil
1254 '(lambda () (flet ((nonsense () nil
))
1255 (defgeneric nonsense
())))))
1259 (typep (funcall (compile nil
1260 '(lambda () (flet ((nonsense-2 () nil
))
1261 (defgeneric nonsense-2
()
1265 ;;; bug reported by Bruno Haible: (setf find-class) using a
1266 ;;; forward-referenced class
1267 (defclass fr-sub
(fr-super) ())
1268 (setf (find-class 'fr-alt
) (find-class 'fr-super
))
1269 (assert (eq (find-class 'fr-alt
) (find-class 'fr-super
)))
1272 ;;; ANSI Figure 4-8: all defined classes. Check that we can define
1273 ;;; methods on all of these.
1275 (defgeneric method-for-defined-classes
(x))
1276 (dolist (c '(arithmetic-error
1277 generic-function simple-error array hash-table
1279 bit-vector integer simple-warning
1280 broadcast-stream list standard-class
1281 built-in-class logical-pathname standard-generic-function
1282 cell-error method standard-method
1283 character method-combination standard-object
1284 class null storage-condition
1285 complex number stream
1286 concatenated-stream package stream-error
1287 condition package-error string
1288 cons parse-error string-stream
1289 control-error pathname structure-class
1290 division-by-zero print-not-readable structure-object
1291 echo-stream program-error style-warning
1292 end-of-file random-state symbol
1293 error ratio synonym-stream
1294 file-error rational t
1295 file-stream reader-error two-way-stream
1296 float readtable type-error
1297 floating-point-inexact real unbound-slot
1298 floating-point-invalid-operation restart unbound-variable
1299 floating-point-overflow sequence undefined-function
1300 floating-point-underflow serious-condition vector
1301 function simple-condition warning
))
1302 (eval `(defmethod method-for-defined-classes ((x ,c
)) (princ x
))))
1303 (assert (string= (with-output-to-string (*standard-output
*)
1304 (method-for-defined-classes #\
3))
1309 ;;; When class definition does not complete due to a bad accessor
1310 ;;; name, do not cause an error when a new accessor name is provided
1311 ;;; during class redefinition
1313 (defun existing-name (object)
1316 (assert-error (defclass redefinition-of-accessor-class
()
1317 ((slot :accessor existing-name
))))
1319 (defclass redefinition-of-accessor-class
()
1320 ((slot :accessor new-name
)))
1324 (load "package-ctor-bug.lisp")
1325 (assert (= (package-ctor-bug:test
) 3))
1326 (delete-package "PACKAGE-CTOR-BUG")
1327 (load "package-ctor-bug.lisp")
1328 (assert (= (package-ctor-bug:test
) 3))
1330 (with-test (:name
(:defmethod
(setf find-class
) integer
))
1333 (deftype defined-type
() 'integer
)
1335 (defmethod method-on-defined-type ((x defined-type
)) x
))
1336 (deftype defined-type-and-class
() 'integer
)
1337 (setf (find-class 'defined-type-and-class
) (find-class 'integer
))
1338 (defmethod method-on-defined-type-and-class
1339 ((x defined-type-and-class
))
1341 (assert (= (method-on-defined-type-and-class 3) 4)))))
1344 (let (#+nil
; no more sb-pcl::*max-emf-precomputation-methods* as of
1346 (sb-pcl::*max-emf-precomputation-methods
* 0))
1347 (eval '(defgeneric bug-281
(x)
1348 (:method-combination
+)
1349 (:method
((x symbol
)) 1)
1350 (:method
+ ((x number
)) x
)))
1351 (assert (= 1 (bug-281 1)))
1352 (assert (= 4.2 (bug-281 4.2)))
1353 (multiple-value-bind (val err
) (ignore-errors (bug-281 'symbol
))
1355 (assert (typep err
'error
))))
1357 ;;; RESTART-CASE and CALL-METHOD
1359 ;;; from Bruno Haible
1361 (defun rc-cm/prompt-for-new-values
()
1362 (format *debug-io
* "~&New values: ")
1363 (finish-output *debug-io
*)
1364 (list (read *debug-io
*)))
1366 (defun rc-cm/add-method-restarts
(form method
)
1367 (let ((block (gensym))
1375 :report
(lambda (stream)
1376 (format stream
"Try calling ~S again." ,method
))
1379 :report
(lambda (stream)
1380 (format stream
"Specify return values for ~S call."
1382 :interactive
(lambda () (rc-cm/prompt-for-new-values
))
1383 (return-from ,block
(values-list l
)))))))))
1385 (defun rc-cm/convert-effective-method
(efm)
1387 (if (eq (car efm
) 'call-method
)
1388 (let ((method-list (third efm
)))
1389 (if (or (typep (first method-list
) 'method
) (rest method-list
))
1390 ;; Reduce the case of multiple methods to a single one.
1391 ;; Make the call to the next-method explicit.
1392 (rc-cm/convert-effective-method
1393 `(call-method ,(second efm
)
1395 (call-method ,(first method-list
) ,(rest method-list
))))))
1396 ;; Now the case of at most one method.
1397 (if (typep (second efm
) 'method
)
1398 ;; Wrap the method call in a RESTART-CASE.
1399 (rc-cm/add-method-restarts
1400 (cons (rc-cm/convert-effective-method
(car efm
))
1401 (rc-cm/convert-effective-method
(cdr efm
)))
1403 ;; Normal recursive processing.
1404 (cons (rc-cm/convert-effective-method
(car efm
))
1405 (rc-cm/convert-effective-method
(cdr efm
))))))
1406 (cons (rc-cm/convert-effective-method
(car efm
))
1407 (rc-cm/convert-effective-method
(cdr efm
))))
1410 (define-method-combination standard-with-restarts
()
1413 (primary () :required t
)
1415 (flet ((call-methods-sequentially (methods)
1416 (mapcar #'(lambda (method)
1417 `(call-method ,method
))
1419 (let ((form (if (or before after
(rest primary
))
1420 `(multiple-value-prog1
1422 ,@(call-methods-sequentially before
)
1423 (call-method ,(first primary
) ,(rest primary
)))
1424 ,@(call-methods-sequentially (reverse after
)))
1425 `(call-method ,(first primary
)))))
1428 `(call-method ,(first around
)
1429 (,@(rest around
) (make-method ,form
)))))
1430 (rc-cm/convert-effective-method form
))))
1432 (defgeneric rc-cm
/testgf16
(x)
1433 (:method-combination standard-with-restarts
))
1434 (defclass rc-cm
/testclass16a
() ())
1435 (defclass rc-cm
/testclass16b
(rc-cm/testclass16a
) ())
1436 (defclass rc-cm
/testclass16c
(rc-cm/testclass16a
) ())
1437 (defclass rc-cm
/testclass16d
(rc-cm/testclass16b rc-cm
/testclass16c
) ())
1438 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16a
))
1440 (not (null (find-restart 'method-redo
)))
1441 (not (null (find-restart 'method-return
)))))
1442 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16b
))
1443 (cons 'b
(call-next-method)))
1444 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16c
))
1445 (cons 'c
(call-next-method)))
1446 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16d
))
1447 (cons 'd
(call-next-method)))
1448 (assert (equal (rc-cm/testgf16
(make-instance 'rc-cm
/testclass16d
))
1451 ;;; test case from Gerd Moellmann
1452 (define-method-combination r-c
/c-m-1
()
1453 ((primary () :required t
))
1454 `(restart-case (call-method ,(first primary
))))
1456 (defgeneric r-c
/c-m-1-gf
()
1457 (:method-combination r-c
/c-m-1
)
1460 (assert (null (r-c/c-m-1-gf
)))
1462 (handler-bind ((warning #'error
))
1463 (eval '(defclass class-for-ctor
/class-slot
()
1464 ((class-slot :initarg
:class-slot
:allocation
:class
))))
1465 (eval '(let ((c1 (make-instance 'class-for-ctor
/class-slot
))
1466 (c2 (make-instance 'class-for-ctor
/class-slot
:class-slot
1)))
1467 (assert (equal (list (slot-value c1
'class-slot
)
1468 (slot-value c2
'class-slot
))
1471 ;;; tests of ctors on anonymous classes
1472 (defparameter *unnamed
* (defclass ctor-unnamed-literal-class
() ()))
1473 (setf (class-name *unnamed
*) nil
)
1474 (setf (find-class 'ctor-unnamed-literal-class
) nil
)
1475 (defparameter *unnamed2
* (defclass ctor-unnamed-literal-class2
() ()))
1476 (defun ctor-unnamed-literal-class ()
1477 (make-instance '#.
*unnamed
*))
1478 (compile 'ctor-unnamed-literal-class
)
1479 (defun ctor-unnamed-literal-class2 ()
1480 (make-instance '#.
(find-class 'ctor-unnamed-literal-class2
)))
1481 (compile 'ctor-unnamed-literal-class2
)
1482 (defun ctor-unnamed-literal-class2/symbol
()
1483 (make-instance 'ctor-unnamed-literal-class2
))
1484 (compile 'ctor-unnamed-literal-class2
/symbol
)
1485 (setf (class-name *unnamed2
*) nil
)
1486 (setf (find-class 'ctor-unnamed-literal-class2
) nil
)
1487 (with-test (:name
(:ctor
:unnamed-before
))
1488 (assert (typep (ctor-unnamed-literal-class) *unnamed
*)))
1489 (with-test (:name
(:ctor
:unnamed-after
))
1490 (assert (typep (ctor-unnamed-literal-class2) *unnamed2
*)))
1491 (with-test (:name
(:ctor
:unnamed-after
/symbol
))
1492 (assert-error (ctor-unnamed-literal-class2/symbol
)))
1494 ;;; classes with slot types shouldn't break if the types don't name
1495 ;;; classes (bug #391)
1496 (defclass slot-type-superclass
() ((slot :type fixnum
)))
1497 (defclass slot-type-subclass
(slot-type-superclass)
1498 ((slot :type
(integer 1 5))))
1499 (let ((instance (make-instance 'slot-type-subclass
)))
1500 (setf (slot-value instance
'slot
) 3))
1502 ;;; ctors where there's a non-standard SHARED-INITIALIZE method and an
1503 ;;; initarg which isn't self-evaluating (kpreid on #lisp 2006-01-29)
1504 (defclass kpreid-enode
()
1505 ((slot :initarg not-a-keyword
)))
1506 (defmethod shared-initialize ((o kpreid-enode
) slots
&key
&allow-other-keys
)
1508 (defun make-kpreid-enode ()
1509 (make-instance 'kpreid-enode
'not-a-keyword
3))
1510 (with-test (:name
(:ctor
:non-keyword-initarg
))
1511 (let ((x (make-kpreid-enode))
1512 (y (make-kpreid-enode)))
1513 (= (slot-value x
'slot
) (slot-value y
'slot
))))
1515 ;;; defining a class hierarchy shouldn't lead to spurious classoid
1516 ;;; errors on TYPEP questions (reported by Tim Moore on #lisp
1518 (defclass backwards-2
(backwards-1) (a b
))
1519 (defclass backwards-3
(backwards-2) ())
1520 (defun typep-backwards-3 (x)
1521 (typep x
'backwards-3
))
1522 (defclass backwards-1
() (a b
))
1523 (assert (not (typep-backwards-3 1)))
1524 (assert (not (typep-backwards-3 (make-instance 'backwards-2
))))
1525 (assert (typep-backwards-3 (make-instance 'backwards-3
)))
1527 (defgeneric remove-method-1
(x)
1528 (:method
((x integer
)) (1+ x
)))
1529 (defgeneric remove-method-2
(x)
1530 (:method
((x integer
)) (1- x
)))
1531 (assert (eq #'remove-method-1
1532 (remove-method #'remove-method-1
1533 (find-method #'remove-method-2
1535 (list (find-class 'integer
))))))
1536 (assert (= (remove-method-1 3) 4))
1537 (assert (= (remove-method-2 3) 2))
1539 ;;; ANSI doesn't require these restarts, but now that we have them we
1540 ;;; better test them too.
1541 (defclass slot-unbound-restart-test
() ((x)))
1542 (let ((test (make-instance 'slot-unbound-restart-test
)))
1543 (assert (not (slot-boundp test
'x
)))
1544 (assert (= 42 (handler-bind ((unbound-slot (lambda (c) (use-value 42 c
))))
1545 (slot-value test
'x
))))
1546 (assert (not (slot-boundp test
'x
)))
1547 (assert (= 13 (handler-bind ((unbound-slot (lambda (c) (store-value 13 c
))))
1548 (slot-value test
'x
))))
1549 (assert (= 13 (slot-value test
'x
))))
1551 ;;; Using class instances as specializers, reported by Pascal Costanza, ref CLHS 7.6.2
1552 (defclass class-as-specializer-test
()
1554 (eval `(defmethod class-as-specializer-test1 ((x ,(find-class 'class-as-specializer-test
)))
1556 (assert (eq 'foo
(class-as-specializer-test1 (make-instance 'class-as-specializer-test
))))
1557 (funcall (compile nil
`(lambda ()
1558 (defmethod class-as-specializer-test2 ((x ,(find-class 'class-as-specializer-test
)))
1560 (assert (eq 'bar
(class-as-specializer-test2 (make-instance 'class-as-specializer-test
))))
1562 ;;; CHANGE-CLASS and tricky allocation.
1563 (defclass foo-to-be-changed
()
1564 ((a :allocation
:class
:initform
1)))
1565 (defclass bar-to-be-changed
(foo-to-be-changed) ())
1566 (defvar *bar-to-be-changed
* (make-instance 'bar-to-be-changed
))
1567 (defclass baz-to-be-changed
()
1568 ((a :allocation
:instance
:initform
2)))
1569 (change-class *bar-to-be-changed
* 'baz-to-be-changed
)
1570 (assert (= (slot-value *bar-to-be-changed
* 'a
) 1))
1572 ;;; proper name and class redefinition
1573 (defvar *to-be-renamed1
* (defclass to-be-renamed1
() ()))
1574 (defvar *to-be-renamed2
* (defclass to-be-renamed2
() ()))
1575 (setf (find-class 'to-be-renamed1
) (find-class 'to-be-renamed2
))
1576 (defvar *renamed1
* (defclass to-be-renamed1
() ()))
1577 (assert (not (eq *to-be-renamed1
* *to-be-renamed2
*)))
1578 (assert (not (eq *to-be-renamed1
* *renamed1
*)))
1579 (assert (not (eq *to-be-renamed2
* *renamed1
*)))
1581 ;;; CLASS-NAME (and various other standardized generic functions) have
1582 ;;; their effective methods precomputed; in the process of rearranging
1583 ;;; (SETF FIND-CLASS) and FINALIZE-INHERITANCE, this broke.
1584 (defclass class-with-odd-class-name-method
()
1585 ((a :accessor class-name
)))
1587 ;;; another case where precomputing (this time on PRINT-OBJECT) and
1588 ;;; lazily-finalized classes caused problems. (report from James Y
1589 ;;; Knight sbcl-devel 20-07-2006)
1591 (defclass base-print-object
() ())
1592 ;;; this has the side-effect of finalizing BASE-PRINT-OBJECT, and
1593 ;;; additionally the second specializer (STREAM) changes the cache
1594 ;;; structure to require two keys, not just one.
1595 (defmethod print-object ((o base-print-object
) (s stream
))
1598 ;;; unfinalized as yet
1599 (defclass sub-print-object
(base-print-object) ())
1600 ;;; the accessor causes an eager finalization
1601 (defclass subsub-print-object
(sub-print-object)
1604 ;;; triggers a discriminating function (and so cache) recomputation.
1605 ;;; The method on BASE-PRINT-OBJECT will cause the system to attempt
1606 ;;; to fill the cache for all subclasses of BASE-PRINT-OBJECT which
1607 ;;; have valid wrappers; however, in the course of doing so, the
1608 ;;; SUB-PRINT-OBJECT class gets finalized, which invalidates the
1609 ;;; SUBSUB-PRINT-OBJECT wrapper; if an invalid wrapper gets into a
1610 ;;; cache with more than one key, then failure ensues.
1611 (reinitialize-instance #'print-object
)
1613 ;;; bug in long-form method combination: if there's an applicable
1614 ;;; method not part of any method group, we need to call
1615 ;;; INVALID-METHOD-ERROR. (MC27 test case from Bruno Haible)
1616 (define-method-combination mc27
()
1618 (ignored (:ignore
:unused
)))
1620 ,@(mapcar #'(lambda (method) `(call-method ,method
)) normal
)))
1621 (defgeneric test-mc27
(x)
1622 (:method-combination mc27
)
1623 (:method
:ignore
((x number
)) (/ 0)))
1624 (assert-error (test-mc27 7))
1626 (define-method-combination mc27prime
()
1628 (ignored (:ignore
)))
1629 `(list 'result
,@(mapcar (lambda (m) `(call-method ,m
)) normal
)))
1630 (defgeneric test-mc27prime
(x)
1631 (:method-combination mc27prime
)
1632 (:method
:ignore
((x number
)) (/ 0)))
1633 (assert (equal '(result) (test-mc27prime 3)))
1634 (assert-error (test-mc27 t
)) ; still no-applicable-method
1636 ;;; more invalid wrappers. This time for a long-standing bug in the
1637 ;;; compiler's expansion for TYPEP on various class-like things, with
1638 ;;; user-visible consequences.
1639 (defclass obsolete-again
() ())
1640 (defvar *obsolete-again
* (make-instance 'obsolete-again
))
1641 (defvar *obsolete-again-hash
* (sxhash *obsolete-again
*))
1642 (make-instances-obsolete (find-class 'obsolete-again
))
1643 (assert (not (streamp *obsolete-again
*)))
1644 (make-instances-obsolete (find-class 'obsolete-again
))
1645 (assert (= (sxhash *obsolete-again
*) *obsolete-again-hash
*))
1646 (compile (defun is-a-structure-object-p (x) (typep x
'structure-object
)))
1647 (make-instances-obsolete (find-class 'obsolete-again
))
1648 (assert (not (is-a-structure-object-p *obsolete-again
*)))
1650 ;;; overeager optimization of slot-valuish things
1651 (defclass listoid
()
1652 ((caroid :initarg
:caroid
)
1653 (cdroid :initarg
:cdroid
:initform nil
)))
1654 (defmethod lengthoid ((x listoid
))
1656 (loop until
(null x
)
1657 do
(incf result
) (setq x
(slot-value x
'cdroid
)))
1659 (with-test (:name
((:setq
:method-parameter
) slot-value
))
1660 (assert (= (lengthoid (make-instance 'listoid
)) 1))
1661 (assert (= (lengthoid
1662 (make-instance 'listoid
:cdroid
1663 (make-instance 'listoid
:cdroid
1664 (make-instance 'listoid
))))
1669 ;;;; Tests for argument parsing in fast-method-functions.
1673 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
1674 (setf (symbol-value 'a
) 'invalid
))
1676 (defmacro test1
(lambda-list values args
&key declarations cnm
)
1678 (fmakunbound 'll-method
)
1679 (fmakunbound 'll-function
)
1680 (defmethod ll-method ,lambda-list
1683 `((when nil
(call-next-method))))
1685 (defun ll-function ,lambda-list
1689 (assert (equal (ll-method ,@args
)
1690 (ll-function ,@args
))))))
1692 (defmacro test
(&rest args
)
1694 (test1 ,@args
:cnm nil
)
1695 (test1 ,@args
:cnm t
)))
1697 ;; Just plain arguments
1700 (test (a b c d e f g h i
) (a b c d e f g h i
) (1 2 3 4 5 6 7 8 9))
1702 (test (*foo
*) (*foo
* (symbol-value '*foo
*)) (1))
1704 (test (a) (a (symbol-value 'a
)) (1)
1705 :declarations
((declare (special a
))))
1709 (test (a &optional b c
) (a b c
) (1))
1710 (test (a &optional b c
) (a b c
) (1 2))
1711 (test (a &optional b c
) (a b c
) (1 2 3))
1713 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1))
1714 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1 2))
1715 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1 2 3))
1717 (test (&optional
*foo
*) (*foo
* (symbol-value '*foo
*)) ())
1718 (test (&optional
*foo
*) (*foo
* (symbol-value '*foo
*)) (1))
1720 (test (&optional
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
) ())
1721 (test (&optional
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
) (1))
1723 (test (&optional a
) (a (symbol-value 'a
)) ()
1724 :declarations
((declare (special a
))))
1725 (test (&optional a
) (a (symbol-value 'a
)) (1)
1726 :declarations
((declare (special a
))))
1728 (test (&optional
(a 'z a-p
)) (a (symbol-value 'a
) a-p
) ()
1729 :declarations
((declare (special a
))))
1730 (test (&optional
(a 'z a-p
)) (a (symbol-value 'a
) a-p
) (1)
1731 :declarations
((declare (special a
))))
1733 (defparameter *count
* 0)
1735 (test (&optional
(a (incf *count
*)) (b (incf *count
*)))
1736 (a b
*count
* (setf *count
* 0))
1739 ;; Keywords with some &RESTs thrown in
1746 (1 :c
3 :c
1 :b
2 :b
4)))
1747 (eval `(test (a &key b c
) (a b c
) ,args
))
1748 (eval `(test (a &key
(b 'b b-p
) (c 'c c-p
))
1751 (eval `(test (a &rest rest
&key
(b 'b b-p
) (c 'c c-p
))
1752 (a b c b-p c-p rest
)
1754 (eval `(test (a &rest
*foo
* &key
(b 'b b-p
) (c 'c c-p
))
1755 (a b c b-p c-p
*foo
* (symbol-value '*foo
*))
1757 (eval `(test (a &rest
*foo
* &key
(b 'b b-p
) (c 'c c-p
))
1758 (a b c b-p c-p
*foo
* (symbol-value '*foo
*))
1760 :declarations
((declare (special b-p
))))))
1764 (:*foo
* 1 :*foo
* 2)))
1765 (eval `(test (&key
*foo
*) (*foo
* (symbol-value '*foo
*)) ,args
))
1766 (eval `(test (&key
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
)
1768 (eval `(test (&key
((:*foo
* a
) 'z foo-p
)) (a (symbol-value 'a
) foo-p
)
1770 (eval `(test (&key
((:*foo
* a
) 'z foo-p
)) (a (symbol-value 'a
) foo-p
)
1772 :declarations
((declare (special a
))))))
1774 (defparameter *count
* 0)
1776 (test (&key
(a (incf *count
*)) (b (incf *count
*)))
1777 (a b
*count
* (setf *count
* 0))
1780 (test (&key a b
&allow-other-keys
) (a b
) (:a
1 :b
2 :c
3))
1782 (defmethod clim-style-lambda-list-test (a b
&optional c d
&key x y
)
1785 (clim-style-lambda-list-test 1 2)
1789 (test (&aux
(a (incf *count
*)) (b (incf *count
*)))
1790 (a b
*count
* (setf *count
* 0))
1793 ;;;; long-form method combination with &rest in :arguments
1794 ;;;; (this had a bug what with fixed in 1.0.4.something)
1795 (define-method-combination long-form-with-
&rest
()
1797 (:arguments x
&rest others
)
1799 ,@(mapcar (lambda (method)
1800 `(call-method ,method
))
1802 (list ,x
(length ,others
))))
1804 (defgeneric test-long-form-with-
&rest
(x &rest others
)
1805 (:method-combination long-form-with-
&rest
))
1807 (defmethod test-long-form-with-&rest
(x &rest others
)
1810 (with-test (:name
(define-method-combination :long-form-with-
&rest
))
1811 (assert (equal '(:foo
13)
1812 (apply #'test-long-form-with-
&rest
:foo
(make-list 13)))))
1814 ;;;; slot-missing for non-standard classes on SLOT-VALUE
1816 ;;;; FIXME: This is arguably not right, actually: CLHS seems to say
1817 ;;;; we should just signal an error at least for built-in classes, but
1818 ;;;; for a while we were hitting NO-APPLICABLE-METHOD, which is definitely
1819 ;;;; wrong -- so test this for now at least.
1821 (defvar *magic-symbol
* (gensym "MAGIC"))
1823 (set *magic-symbol
* 42)
1825 (defmethod slot-missing (class instance
(slot-name (eql *magic-symbol
*)) op
1828 (setf (symbol-value *magic-symbol
*) new
)
1829 (symbol-value *magic-symbol
*)))
1831 (with-test (:name
(slot-missing :non-standard-classes
))
1832 (assert (eql 42 (slot-value (cons t t
) *magic-symbol
*)))
1833 (assert (eql 13 (setf (slot-value 123 *magic-symbol
*) 13)))
1834 (assert (eql 13 (slot-value 'foobar
*magic-symbol
*))))
1836 ;;;; Built-in structure and condition layouts should have NIL in
1837 ;;;; LAYOUT-FOR-STD-CLASS-P, and classes should have T.
1839 (with-test (:name
(sb-pcl::layout-for-std-class-p
:builtin
))
1840 (assert (not (sb-pcl::layout-for-std-class-p
(sb-pcl::find-layout
'warning
))))
1841 (assert (not (sb-pcl::layout-for-std-class-p
(sb-pcl::find-layout
'hash-table
))))
1842 (assert (eq t
(sb-pcl::layout-for-std-class-p
(sb-pcl::find-layout
'standard-object
)))))
1844 ;;;; bug 402: PCL used to warn about non-standard declarations
1845 (declaim (declaration bug-402-d
))
1846 (defgeneric bug-402-gf
(x))
1847 (with-test (:name
(defmethod :non-standard-declaration
:bug-402
))
1848 (handler-bind ((warning #'error
))
1849 (eval '(defmethod bug-402-gf (x)
1850 (declare (bug-402-d x
))
1853 ;;;; non-keyword :default-initargs + :before method on shared initialize
1854 ;;;; interacted badly with CTOR optimizations
1855 (defclass ctor-default-initarg-problem
()
1856 ((slot :initarg slotto
))
1857 (:default-initargs slotto
123))
1858 (defmethod shared-initialize :before
((instance ctor-default-initarg-problem
) slot-names
&rest initargs
)
1859 (format t
"~&Rock on: ~A~%" initargs
))
1860 (defun provoke-ctor-default-initarg-problem ()
1861 (make-instance 'ctor-default-initarg-problem
))
1862 (with-test (:name
(make-instance :non-keyword-default-initargs
1863 shared-initialize
:before
))
1864 (handler-bind ((warning #'error
))
1865 (assert (= 123 (slot-value (provoke-ctor-default-initarg-problem) 'slot
)))))
1867 ;;;; discriminating net on streams used to generate code deletion notes on
1869 (defgeneric stream-fd
(stream direction
))
1870 (defmethod stream-fd ((stream sb-sys
:fd-stream
) direction
)
1871 (declare (ignore direction
))
1872 (sb-sys:fd-stream-fd stream
))
1873 (defmethod stream-fd ((stream synonym-stream
) direction
)
1874 (stream-fd (symbol-value (synonym-stream-symbol stream
)) direction
))
1875 (defmethod stream-fd ((stream two-way-stream
) direction
)
1879 (two-way-stream-input-stream stream
) direction
))
1882 (two-way-stream-output-stream stream
) direction
))))
1883 (with-test (:name
(:discriminating-name
:code-deletion-note
))
1884 (handler-bind ((compiler-note #'error
))
1885 (stream-fd sb-sys
:*stdin
* :output
)
1886 (stream-fd sb-sys
:*stdin
* :output
)))
1888 (with-test (:name
:bug-380
)
1889 (defclass bug-380
()
1890 ((slot :accessor bug380-slot
)))
1891 (fmakunbound 'foo-slot
)
1892 (defgeneric foo-slot
(x y z
))
1894 ((slot :accessor foo-slot-value
))))
1896 ;;; SET and (SETF SYMBOL-VALUE) used to confuse permuation vector
1899 ((x :initform
:fih
)))
1901 ((x :initform
:fah
)))
1902 (declaim (special *fih
*))
1903 (defmethod fihfah ((*fih
* fih
))
1904 (set '*fih
* (make-instance 'fah
))
1905 (list (slot-value *fih
* 'x
)
1906 (eval '(slot-value *fih
* 'x
))))
1907 (defmethod fihfah ((fah fah
))
1908 (declare (special fah
))
1909 (set 'fah
(make-instance 'fih
))
1910 (list (slot-value fah
'x
)
1911 (eval '(slot-value fah
'x
))))
1912 (with-test (:name
:set-of-a-method-specializer
)
1913 (assert (equal '(:fah
:fah
) (fihfah (make-instance 'fih
))))
1914 (assert (equal '(:fih
:fih
) (fihfah (make-instance 'fah
)))))
1916 (defmethod no-implicit-declarations-for-local-specials ((faax double-float
))
1917 (declare (special faax
))
1918 (set 'faax
(when (< faax
0) (- faax
)))
1920 (with-test (:name
:no-implicit-declarations-for-local-specials
)
1921 (assert (not (no-implicit-declarations-for-local-specials 1.0d0
))))
1923 (defstruct bug-357-a
1926 (slot3 (coerce pi
'single-float
) :type single-float
))
1927 (defclass bug-357-b
(bug-357-a)
1928 ((slot2 :initform
't2
)
1929 (slot4 :initform -
44)
1932 (slot7 :initform
(floor (* pi pi
)))
1933 (slot8 :initform
88))
1934 (:metaclass structure-class
))
1935 (defstruct (bug-357-c (:include bug-357-b
(slot8 -
88) (slot5 :ok
)))
1938 (slot11 (floor (exp 3))))
1939 (with-test (:name
:bug-357
)
1941 (list (bug-357-c-slot1 x
)
1950 (bug-357-c-slot10 x
)
1951 (bug-357-c-slot11 x
))))
1952 (let ((base (slots (make-bug-357-c))))
1953 (assert (equal base
(slots (make-instance 'bug-357-c
))))
1954 (assert (equal base
'(nil t2
3.1415927 -
44 :ok t
9 -
88 nil t
20))))))
1956 (defclass class-slot-shared-initialize
()
1957 ((a :allocation
:class
:initform
:ok
)))
1958 (with-test (:name
:class-slot-shared-initialize
)
1959 (let ((x (make-instance 'class-slot-shared-initialize
)))
1960 (assert (eq :ok
(slot-value x
'a
)))
1961 (slot-makunbound x
'a
)
1962 (assert (not (slot-boundp x
'a
)))
1963 (shared-initialize x
'(a))
1964 (assert (slot-boundp x
'a
))
1965 (assert (eq :ok
(slot-value x
'a
)))))
1967 (declaim (ftype (function (t t t
) (values single-float
&optional
))
1968 i-dont-want-to-be-clobbered-1
1969 i-dont-want-to-be-clobbered-2
))
1970 (defgeneric i-dont-want-to-be-clobbered-1
(t t t
))
1971 (defmethod i-dont-want-to-be-clobbered-2 ((x cons
) y z
)
1973 (defun i-cause-an-gf-info-update ()
1974 (i-dont-want-to-be-clobbered-2 t t t
))
1975 (with-test (:name
:defgeneric-should-clobber-ftype
)
1976 ;; (because it doesn't check the argument or result types)
1977 (assert (equal '(function (t t t
) *)
1978 (sb-kernel:type-specifier
1979 (sb-int:info
:function
1980 :type
'i-dont-want-to-be-clobbered-1
))))
1981 (assert (equal '(function (t t t
) *)
1982 (sb-kernel:type-specifier
1983 (sb-int:info
:function
1984 :type
'i-dont-want-to-be-clobbered-2
))))
1985 (assert (eq :defined-method
1986 (sb-int:info
:function
1987 :where-from
'i-dont-want-to-be-clobbered-1
)))
1988 (assert (eq :defined-method
1989 (sb-int:info
:function
1990 :where-from
'i-dont-want-to-be-clobbered-2
))))
1992 (with-test (:name
:bogus-parameter-specializer-name-error
)
1995 (eval `(defmethod #:fii
((x "a string")) 'string
))
1996 (sb-int:reference-condition
(c)
1997 (when (member '(:ansi-cl
:macro defmethod
)
1998 (sb-int:reference-condition-references c
)
2002 (defclass remove-default-initargs-test
()
2003 ((x :initarg
:x
:initform
42)))
2004 (defclass remove-default-initatgs-test
()
2005 ((x :initarg
:x
:initform
42))
2006 (:default-initargs
:x
0))
2007 (defclass remove-default-initargs-test
()
2008 ((x :initarg
:x
:initform
42)))
2009 (with-test (:name
:remove-default-initargs
)
2010 (assert (= 42 (slot-value (make-instance 'remove-default-initargs-test
)
2013 (with-test (:name
:bug-485019
)
2014 ;; there was a bug in WALK-SETQ, used in method body walking, in the
2015 ;; presence of declarations on symbol macros.
2016 (defclass bug-485019
()
2017 ((array :initarg
:array
)))
2018 (defmethod bug-485019 ((bug-485019 bug-485019
))
2019 (with-slots (array) bug-485019
2020 (declare (type (or null simple-array
) array
))
2021 (setf array
(make-array 4)))
2023 (bug-485019 (make-instance 'bug-485019
)))
2025 ;;; The compiler didn't propagate the declarared type before applying
2026 ;;; the transform for (SETF SLOT-VALUE), so the generic accessor was used.
2027 (defstruct foo-520366
2029 (defun quux-520366 (cont)
2031 (defun bar-520366 (foo-struct)
2032 (declare (type foo-520366 foo-struct
))
2033 (with-slots (slot) foo-struct
2035 (quux-520366 #'(lambda ()
2039 (with-test (:name
:bug-520366
)
2040 (let ((callees (find-named-callees #'bar-520366
)))
2041 (assert (equal (list #'quux-520366
) callees
))))
2043 (defgeneric no-applicable-method
/retry
(x))
2044 (defmethod no-applicable-method/retry
((x string
))
2046 (with-test (:name
:no-applicable-method
/retry
)
2047 (assert (equal "cons"
2048 (handler-bind ((error
2050 (declare (ignore c
))
2051 (let ((r (find-restart 'sb-pcl
::retry
)))
2053 (eval `(defmethod no-applicable-method/retry
((x cons
))
2055 (invoke-restart r
))))))
2056 (no-applicable-method/retry
(cons t t
))))))
2058 (defgeneric no-primary-method
/retry
(x))
2059 (defmethod no-primary-method/retry
:before
(x) (assert x
))
2060 (with-test (:name
:no-primary-method
/retry
)
2061 (assert (equal "ok!"
2062 (handler-bind ((error
2064 (declare (ignore c
))
2065 (let ((r (find-restart 'sb-pcl
::retry
)))
2067 (eval `(defmethod no-primary-method/retry
(x)
2069 (invoke-restart r
))))))
2070 (no-primary-method/retry
(cons t t
))))))
2072 ;;; test that a cacheing strategy for make-instance initargs checking
2073 ;;; can handle class redefinitions
2075 (defun cacheing-initargs-redefinitions-make-instances
2076 (&optional
(initarg :slot
))
2077 (declare (notinline make-instance
))
2078 (make-instance 'cacheing-initargs-redefinitions-check
)
2079 (make-instance 'cacheing-initargs-redefinitions-check initarg
3))
2081 (defclass cacheing-initargs-redefinitions-check
()
2082 ((slot :initarg
:slot
)))
2084 (with-test (:name
(make-instance :initargs-checking-before-redefinition
))
2085 (make-instance 'cacheing-initargs-redefinitions-check
)
2086 (make-instance 'cacheing-initargs-redefinitions-check
:slot
3)
2087 (cacheing-initargs-redefinitions-make-instances :slot
)
2088 (assert-error (cacheing-initargs-redefinitions-make-instances :slot2
)))
2090 (defclass cacheing-initargs-redefinitions-check
()
2091 ((slot :initarg
:slot2
)))
2093 (with-test (:name
(make-instance :initargs-checking-after-redefinition
))
2094 (make-instance 'cacheing-initargs-redefinitions-check
)
2095 (make-instance 'cacheing-initargs-redefinitions-check
:slot2
3)
2096 (cacheing-initargs-redefinitions-make-instances :slot2
)
2097 (assert-error (cacheing-initargs-redefinitions-make-instances :slot
)))
2099 (defmethod initialize-instance :after
2100 ((class cacheing-initargs-redefinitions-check
) &key slot
)
2103 (with-test (:name
(make-instance :initargs-checking-new-method-initargs
))
2104 (make-instance 'cacheing-initargs-redefinitions-check
)
2105 (make-instance 'cacheing-initargs-redefinitions-check
:slot2
3)
2106 (cacheing-initargs-redefinitions-make-instances :slot2
)
2107 (let ((thing (cacheing-initargs-redefinitions-make-instances :slot
)))
2108 (assert (not (slot-boundp thing
'slot
)))))
2113 (with-test (:name
(defmethod :specializer-builtin-class-alias
:bug-618387
))
2114 (let ((alias (gensym)))
2115 (setf (find-class alias
) (find-class 'symbol
))
2116 (eval `(defmethod lp-618387 ((s ,alias
))
2118 (assert (equal "FOO" (funcall 'lp-618387
:foo
)))))
2120 (with-test (:name
(defmethod :pcl-spurious-ignore-warnings
))
2121 (defgeneric no-spurious-ignore-warnings
(req &key key
))
2122 (handler-bind ((warning (lambda (x) (error "~A" x
))))
2124 '(defmethod no-spurious-ignore-warnings ((req number
) &key key
)
2125 (declare (ignore key
))
2126 (check-type req integer
))))
2127 (defgeneric should-get-an-ignore-warning
(req &key key
))
2129 (handler-bind ((warning (lambda (c) (setq warnings
1) (muffle-warning c
))))
2130 (eval '(defmethod should-get-an-ignore-warning ((req integer
) &key key
)
2131 (check-type req integer
))))
2132 (assert (= warnings
1))))
2134 (defgeneric generic-function-pretty-arglist-optional-and-key
(req &optional opt
&key key
)
2135 (:method
(req &optional opt
&key key
)
2136 (list req opt key
)))
2138 (with-test (:name
:generic-function-pretty-arglist-optional-and-key
)
2139 (handler-bind ((warning #'error
))
2140 ;; Used to signal a style-warning
2141 (assert (equal '(req &optional opt
&key key
)
2142 (sb-pcl::generic-function-pretty-arglist
2143 #'generic-function-pretty-arglist-optional-and-key
)))))
2145 (with-test (:name
:bug-894202
)
2148 (let ((name (gensym "FOO"))
2149 (decl (gensym "BAR")))
2150 (eval `(defgeneric ,name
()
2151 (declare (,decl
)))))
2155 (with-test (:name
:bug-898331
)
2156 (handler-bind ((warning #'error
))
2157 (eval `(defgeneric bug-898331
(request type remaining-segment-requests all-requests
)))
2158 (eval `(defmethod bug-898331 ((request cons
) (type (eql :cancel
))
2159 remaining-segment-requests
2160 all-segment-requests
)
2161 (declare (ignore all-segment-requests
))
2162 (check-type request t
)))))
2164 (with-test (:name
(defmethod :bug-1001799
))
2165 ;; compilation of the defmethod used to cause infinite recursion
2166 (let ((pax (gensym "PAX"))
2167 (pnr (gensym "PNR"))
2168 (sup (gensym "SUP"))
2169 (frob (gensym "FROB"))
2170 (sb-ext:*evaluator-mode
* :compile
))
2173 (declaim (optimize (speed 1) (space 1) (safety 3) (debug 3) (compilation-speed 1)))
2174 (defclass ,pax
(,sup
)
2175 ((,pnr
:type
(or null
,pnr
))))
2176 (defclass ,pnr
(,sup
)
2177 ((,pax
:type
(or null
,pax
))))
2180 (defmethod ,frob
((pnr ,pnr
))
2181 (slot-value pnr
',pax
))))))
2183 (with-test (:name
:bug-1099708
)
2184 (defclass bug-1099708
()
2185 ((slot-1099708 :initarg
:slot-1099708
)))
2186 ;; caused infinite equal testing in function name lookup
2189 (defun make-1099708-1 ()
2190 (make-instance 'bug-1099708
:slot-1099708
'#1= (1 2 .
#1#)))
2191 (defun make-1099708-2 ()
2192 (make-instance 'bug-1099708
:slot-1099708
'#2= (1 2 .
#2#)))))
2193 (assert (not (eql (slot-value (make-1099708-1) 'slot-1099708
)
2194 (slot-value (make-1099708-2) 'slot-1099708
)))))
2196 (with-test (:name
:bug-1099708b-list
)
2197 (defclass bug-1099708b-list
()
2198 ((slot-1099708b-list :initarg
:slot-1099708b-list
)))
2201 (defun make-1099708b-list-1 ()
2202 (make-instance 'bug-1099708b-list
:slot-1099708b-list
'(some value
)))
2203 (defun make-1099708b-list-2 ()
2204 (make-instance 'bug-1099708b-list
:slot-1099708b-list
'(some value
)))))
2205 (assert (eql (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)
2206 (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)))
2207 (assert (eql (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)
2208 (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)))
2209 (assert (not (eql (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)
2210 (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)))))
2212 (with-test (:name
:bug-1099708b-string
)
2213 (defclass bug-1099708b-string
()
2214 ((slot-1099708b-string :initarg
:slot-1099708b-string
)))
2217 (defun make-1099708b-string-1 ()
2218 (make-instance 'bug-1099708b-string
:slot-1099708b-string
"string"))
2219 (defun make-1099708b-string-2 ()
2220 (make-instance 'bug-1099708b-string
:slot-1099708b-string
"string"))))
2221 (assert (eql (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)
2222 (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)))
2223 (assert (eql (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)
2224 (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)))
2225 (assert (not (eql (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)
2226 (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)))))
2228 (with-test (:name
:bug-1099708b-bitvector
)
2229 (defclass bug-1099708b-bitvector
()
2230 ((slot-1099708b-bitvector :initarg
:slot-1099708b-bitvector
)))
2233 (defun make-1099708b-bitvector-1 ()
2234 (make-instance 'bug-1099708b-bitvector
:slot-1099708b-bitvector
#*1011))
2235 (defun make-1099708b-bitvector-2 ()
2236 (make-instance 'bug-1099708b-bitvector
:slot-1099708b-bitvector
#*1011))))
2237 (assert (eql (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)
2238 (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)))
2239 (assert (eql (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)
2240 (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)))
2241 (assert (not (eql (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)
2242 (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)))))
2244 (with-test (:name
:bug-1099708b-pathname
)
2245 (defclass bug-1099708b-pathname
()
2246 ((slot-1099708b-pathname :initarg
:slot-1099708b-pathname
)))
2249 (defun make-1099708b-pathname-1 ()
2250 (make-instance 'bug-1099708b-pathname
:slot-1099708b-pathname
#p
"pn"))
2251 (defun make-1099708b-pathname-2 ()
2252 (make-instance 'bug-1099708b-pathname
:slot-1099708b-pathname
#p
"pn"))))
2253 (assert (eql (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)
2254 (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)))
2255 (assert (eql (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)
2256 (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)))
2257 (assert (not (eql (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)
2258 (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)))))
2260 (with-test (:name
:bug-1099708c-list
)
2261 (defclass bug-1099708c-list
()
2262 ((slot-1099708c-list :initarg
:slot-1099708c-list
)))
2265 (defun make-1099708c-list-1 ()
2266 (make-instance 'bug-1099708c-list
:slot-1099708c-list
#1='(some value
)))
2267 (defun make-1099708c-list-2 ()
2268 (make-instance 'bug-1099708c-list
:slot-1099708c-list
#1#))))
2269 (assert (eql (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)
2270 (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)))
2271 (assert (eql (slot-value (make-1099708c-list-2) 'slot-1099708c-list
)
2272 (slot-value (make-1099708c-list-2) 'slot-1099708c-list
)))
2273 (assert (eql (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)
2274 (slot-value (make-1099708c-list-2) 'slot-1099708c-list
))))
2278 ;;; Define a class and force the "fallback" constructor generator to be
2279 ;;; used by having a HAIRY-AROUND-OR-NONSTANDARD-PRIMARY-METHOD-P on
2280 ;;; SHARED-INITIALIZE.
2281 (defclass bug-1179858
()
2282 ((foo :initarg
:foo
:reader bug-1179858-foo
))
2283 (:default-initargs
:foo
(error "Should not be evaluated")))
2284 (defmethod shared-initialize :around
((instance bug-1179858
) (slot-names t
) &key
)
2287 (with-test (:name
(make-instance :fallback-generator-initarg-handling
:bug-1179858
))
2288 ;; Now compile a lambda containing MAKE-INSTANCE to exercise the
2289 ;; fallback constructor generator. Call the resulting compiled
2290 ;; function to trigger the bug.
2291 (funcall (compile nil
'(lambda () (make-instance 'bug-1179858
:foo t
)))))
2293 ;;; Other brokenness, found while investigating: fallback-generator
2294 ;;; handling of non-keyword initialization arguments
2295 (defclass bug-1179858b
()
2296 ((foo :initarg foo
:reader bug-1179858b-foo
))
2297 (:default-initargs foo
14))
2298 (defmethod shared-initialize :around
((instance bug-1179858b
) (slot-names t
) &key
)
2301 (with-test (:name
(make-instance :fallback-generator-non-keyword-initarg
:bug-1179858
))
2302 (flet ((foo= (n i
) (= (bug-1179858b-foo i
) n
)))
2304 (foo= 14 (funcall (compile nil
'(lambda () (make-instance 'bug-1179858b
))))))
2306 (foo= 15 (funcall (compile nil
'(lambda () (make-instance 'bug-1179858b
'foo
15))))))))
2308 (with-test (:name
(:cpl-violation-setup
:bug-309076
))
2311 (defclass bug-309076-broken-class
(standard-class) ()
2312 (:metaclass sb-mop
:funcallable-standard-class
))
2313 (sb-mop:finalize-inheritance
(find-class 'bug-309076-broken-class
)))))
2315 (with-test (:name
(:cpl-violation-irrelevant-class
:bug-309076
))
2316 (defclass bug-309076-class
(standard-class) ())
2317 (defmethod sb-mop:validate-superclass
((x bug-309076-class
) (y standard-class
)) t
)
2318 (assert (typep (make-instance 'bug-309076-class
) 'bug-309076-class
)))
2321 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
2327 (declare (special a
))
2332 (sb-mop:make-method-lambda
2334 (find-method #'b
() ())
2335 '(lambda () (declare (special a
)) a
)
2340 (with-test (:name
:make-method-lambda-leakage
)
2341 ;; lambda list of X leaks into the invocation of make-method-lambda
2342 ;; during code-walking performed by make-method-lambda invoked by
2344 (sb-cltl2:macroexpand-all
'(defmethod x (a) (macro))))
2346 (with-test (:name
(defmethod :undefined-function
:bug-503095
))
2347 (flet ((test-load (file)
2348 (let (implicit-gf-warning)
2350 ((sb-ext:implicit-generic-function-warning
2352 (setf implicit-gf-warning x
)
2353 (muffle-warning x
)))
2354 ((or warning error
) #'error
))
2356 (assert implicit-gf-warning
))))
2357 (multiple-value-bind (fasl warnings errorsp
) (compile-file "bug-503095.lisp")
2359 (progn (assert (and fasl
(not warnings
) (not errorsp
)))
2361 (and fasl
(delete-file fasl
))))
2362 (test-load "bug-503095-2.lisp")))
2364 (with-test (:name
:accessor-and-plain-method
)
2365 (defclass a-633911
()
2366 ((x-633911 :initform nil
2367 :accessor x-633911
)))
2369 (defmethod x-633911 ((b a-633911
)) 10)
2371 (defclass b-633911
()
2372 ((x-633911 :initform nil
2373 :accessor x-633911
)))
2375 (assert (= (x-633911 (make-instance 'a-633911
)) 10)))
2377 (with-test (:name
(built-in-class :subclass error
))
2379 (when (and (class-name c
) (typep c
'built-in-class
))
2380 (assert-error (eval `(defclass ,(gensym) (,(class-name c
))
2382 (sb-pcl::map-all-classes
#'mapper
)))
2384 (defclass slot-value-using-class-a
() ())
2385 (defclass slot-value-using-class-b
() (x))
2387 (with-test (:name
:svuc-with-bad-slotd
)
2388 (let* ((a (make-instance 'slot-value-using-class-a
))
2389 (b (make-instance 'slot-value-using-class-b
))
2390 (slotd (car (sb-mop:class-slots
(class-of b
)))))
2391 (assert-error (sb-mop:slot-value-using-class
(class-of a
) a slotd
))
2392 (assert-error (setf (sb-mop:slot-value-using-class
(class-of a
) a slotd
) t
))))
2394 ;; A test that the *FGENS* cache works.
2395 ;; This is not a test in the CLOS problem domain, but in the implementation
2396 ;; of discriminating functions.
2397 (defgeneric f
(x y
) (:method
(x y
) (+ x y
)))
2398 (defgeneric g
(x y
) (:method
(x y
) (* x y
)))
2399 (with-test (:name
:fgens-sharing
)
2400 (let ((count0 (hash-table-count sb-pcl
::*fgens
*))
2402 (count1 (hash-table-count sb-pcl
::*fgens
*))
2404 (count2 (hash-table-count sb-pcl
::*fgens
*)))
2405 (declare (ignore foo bar
))
2406 (assert (= count0 count1 count2
))))
2409 ;;; Classes shouldn't be their own direct or indirect superclasses or
2412 (with-test (:name
(sb-mop:ensure-class
:class-is-direct-superclass
2415 (defclass class-with-self-as-superclass
(class-with-self-as-superclass) ())))
2417 (with-test (:name
(sb-mop:ensure-class
:superclass-cycle
:bug-1418883
))
2418 ;; These have a superclass cycle from the beginning.
2419 (defclass class-with-superclass-cycle1
(class-with-superclass-cycle2) ())
2421 (defclass class-with-superclass-cycle2
(class-with-superclass-cycle1) ())))
2423 (with-test (:name
(sb-mop:ensure-class
:self-metaclass
))
2424 ;; These have a superclass cycle from the beginning.
2426 (defclass class-with-self-as-metaclass
() ()
2427 (:metaclass class-with-self-as-metaclass
))))
2429 (with-test (:name
(sb-pcl::update-class
:class-becomes-direct-superclass
2431 (defclass class-with-eventual-self-as-superclass
() ())
2432 ;; Update class to introduce superclass.
2434 (defclass class-with-eventual-self-as-superclass
2435 (class-with-eventual-self-as-superclass) ())))
2437 (with-test (:name
(sb-pcl::update-class
:superclasses-become-cyclic
2439 ;; Nothing wrong with these.
2440 (defclass class-with-eventual-superclass-cycle1
() ())
2441 (defclass class-with-eventual-superclass-cycle2
2442 (class-with-eventual-superclass-cycle1) ())
2443 ;; Update first class to introduce the superclass cycle.
2445 (defclass class-with-eventual-superclass-cycle1
2446 (class-with-eventual-superclass-cycle2) ())))
2448 (with-test (:name
(sb-pcl::update-class
:becomses-own-metaclass
))
2449 (defclass class-with-eventual-self-as-metaclass
() ())
2450 ;; Try to update metaclass to self.
2452 (defclass class-with-eventual-self-as-metaclass
() ()
2453 (:metaclass class-with-eventual-self-as-metaclass
))))