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 #+interpreter
(invoke-restart 'run-tests
::skip-file
)
16 (load "compiler-test-util.lisp")
17 (defpackage "CLOS-IMPURE"
18 (:use
"CL" "SB-EXT" "ASSERTOID" "TEST-UTIL" "COMPILER-TEST-UTIL"))
19 (in-package "CLOS-IMPURE")
21 ;;; It should be possible to do DEFGENERIC and DEFMETHOD referring to
22 ;;; structure types defined earlier in the file.
23 (defstruct struct-a x y
)
24 (defstruct struct-b x y z
)
25 (defmethod wiggle ((a struct-a
))
28 (defgeneric jiggle
(arg))
29 (defmethod jiggle ((a struct-a
))
32 (defmethod jiggle ((b struct-b
))
37 (with-test (:name
(defmethod defstruct :same-file
))
38 (assert (= (wiggle (make-struct-a :x
6 :y
5))
39 (jiggle (make-struct-b :x
19 :y
6 :z
2)))))
41 ;;; Compiling DEFGENERIC should prevent "undefined function" style
42 ;;; warnings from code within the same file.
43 (defgeneric gf-defined-in-this-file
(x y
))
44 (defun function-using-gf-defined-in-this-file (x y n
)
46 (gf-defined-in-this-file x y
)))
48 ;;; Until Martin Atzmueller ported Pierre Mai's CMU CL fixes in
49 ;;; sbcl-0.6.12.25, the implementation of NO-APPLICABLE-METHOD was
50 ;;; broken in such a way that the code here would signal an error.
51 (defgeneric zut-n-a-m
(a b c
))
52 (defmethod zut-n-a-m :around
(a b
(c symbol
)) nil
)
53 (defmethod no-applicable-method ((zut-n-a-m (eql #'zut-n-a-m
)) &rest args
)
54 (declare (ignore args
))
55 :no-applicable-method
)
56 (defmethod sb-pcl:no-primary-method
((zut-n-a-m (eql #'zut-n-a-m
)) &rest args
)
57 (declare (ignore args
))
59 (with-test (:name no-applicable-method
)
60 (assert (eq :no-applicable-method
(zut-n-a-m 1 2 3))))
61 (with-test (:name
:no-primary-method
)
62 (assert (eq :no-primary-method
(zut-n-a-m 1 2 t
))))
64 ;;; bug reported and fixed by Alexey Dejneka sbcl-devel 2001-09-10:
65 ;;; This DEFGENERIC shouldn't cause an error.
66 (defgeneric ad-gf
(a) (:method
:around
(x) x
))
68 ;;; DEFGENERIC and DEFMETHOD shouldn't accept &REST when it's not
69 ;;; followed by a variable:
70 ;;; e.g. (DEFMETHOD FOO ((X T) &REST) NIL) should signal an error.
71 ;;; Of course most of these are totally redundant
72 ;;; now that there is only one function to parse all lambda lists.
73 (eval-when (:load-toplevel
:compile-toplevel
:execute
)
74 (defmacro expect-error
(form)
75 `(multiple-value-bind (res condition
)
76 (let ((*error-output
* (make-broadcast-stream)))
77 (ignore-errors (eval ',form
))) ; delay until *error-output* is bound
78 (declare (ignore res
))
79 (typep condition
'error
))))
80 (assert (expect-error (defmethod foo0 ((x t
) &rest
) nil
)))
81 (assert (expect-error (defgeneric foo1
(x &rest
))))
82 (assert (expect-error (defgeneric foo2
(x a
&rest
))))
83 (defgeneric foo3
(x &rest y
))
84 (defmethod foo3 ((x t
) &rest y
) y nil
)
85 (defgeneric foo4
(x &rest z
&key y
))
86 (defmethod foo4 ((x t
) &rest z
&key y
) z y nil
)
87 (assert (expect-error (defgeneric foo5
(x &rest
))))
88 (assert (expect-error (defmethod foo6 (x &rest
))))
90 ;;; legal method specializers
91 (defclass bug-525916-1
() ())
92 (defclass bug-525916-2
() ())
93 (with-test (:name
(defmethod :specializer-syntax
:bug-525916
))
94 (assert (expect-error (defmethod invalid ((arg)) arg
)))
95 (assert (expect-error (defmethod invalid (nil) 1)))
96 (assert (expect-error (defmethod invalid ((arg . bug-525916-1
)) arg
)))
97 (assert (expect-error (defmethod invalid ((arg bug-525916-1 bug-525916-2
)) arg
))))
99 ;;; more lambda-list checking
101 ;;; DEFGENERIC lambda lists are subject to various limitations, as per
102 ;;; section 3.4.2 of the ANSI spec. Since Alexey Dejneka's patch for
103 ;;; bug 191-b ca. sbcl-0.7.22, these limitations should be enforced.
104 (flet ((test-case (operator lambda-list
105 &optional expect-failure-p expect-warnings-p
&rest messages
)
107 (fun failure-p warnings style-warnings notes errors
)
108 (checked-compile `(lambda () (,operator
,(gensym) ,lambda-list
))
109 :allow-failure expect-failure-p
110 :allow-warnings expect-warnings-p
111 :allow-style-warnings expect-warnings-p
)
112 (declare (ignore fun notes
))
113 (let ((warnings (append style-warnings warnings
)))
114 (when expect-failure-p
(assert failure-p
))
115 (when expect-warnings-p
(assert warnings
))
116 (assert (= (length messages
) (+ (length warnings
) (length errors
))))
117 (loop for message in messages
118 for error in
(append warnings errors
)
119 do
(assert (search message
(princ-to-string error
))))))))
121 (with-test (:name
(defgeneric :lambda-list
))
123 (lambda (spec) (apply #'test-case
'defgeneric spec
))
126 t nil
"Required argument is not a symbol: \"a\"")
129 ;; repeated names and keywords
131 t nil
"The variable X occurs more than once")
133 t nil
"The variable X occurs more than once")
135 t nil
"The variable X occurs more than once")
137 t nil
"The variable X occurs more than once")
139 t nil
"The keyword :X occurs more than once")
140 ((&key
((:x a
)) ((:x b
)))
141 t nil
"The keyword :X occurs more than once")
142 ;; illegal variable names
144 t nil
"NIL cannot be used")
146 t nil
":PI is a keyword and cannot be used")
148 t nil
"COMMON-LISP:PI names a defined constant")
149 ;; forbidden default or supplied-p for &OPTIONAL or &KEY arguments
151 t nil
"Invalid &OPTIONAL argument specifier (Y 0)")
153 ((x y
&key
(z :z z-p
))
154 t nil
"Invalid &KEY argument specifier (Z :Z Z-P)")
156 ((x &optional
(y 0) &key z
)
158 "&OPTIONAL and &KEY found in the same lambda list"
159 "Invalid &OPTIONAL argument specifier (Y 0)")
160 ((x &optional y
&key z
)
161 nil t
"&OPTIONAL and &KEY found in the same lambda list")
162 ((x &optional y
&key
(z :z
))
164 "&OPTIONAL and &KEY found in the same lambda list"
165 "Invalid &KEY argument specifier (Z :Z)")
166 ((&optional
&key
(k :k k-p
))
167 t nil
"Invalid &KEY argument specifier (K :K K-P)")
170 ((x y z
&optional a
&aux g h
)
171 t nil
"&AUX is not allowed in a generic function lambda list")
172 ((x y z
&optional a
))
174 t nil
"&AUX is not allowed in a generic function lambda list")
175 ;; also can't use bogoDEFMETHODish type-qualifier-ish decorations
176 ;; on required arguments
178 t nil
"Required argument is not a symbol: (ARG T)"))))
180 (with-test (:name
(defmethod :lambda-list
))
182 (lambda (spec) (apply #'test-case
'defmethod
spec))
183 '(;; Invalid specialized required argument
185 t nil
"arg is not a non-NIL symbol or a list of two elements: (X T T)")
186 ;; Repeated names and keywords
188 t nil
"The variable X occurs more than once")
190 t nil
"The variable X occurs more than once")
192 t nil
"The variable X occurs more than once")
194 t nil
"The variable X occurs more than once")
196 t nil
"The keyword :X occurs more than once")
197 ;; Illegal variable names
199 t nil
"NIL cannot be used")
201 t nil
":PI is a keyword and cannot be used")
203 t nil
"COMMON-LISP:PI names a defined constant")))))
206 ;;; Explicit :metaclass option with structure-class and
209 (defclass structure-class-foo1
() () (:metaclass cl
:structure-class
))
210 (defclass structure-class-foo2
(structure-class-foo1)
211 () (:metaclass cl
:structure-class
))
212 (with-test (:name
(defclass :metaclass cl
:structure-class
))
213 (assert (typep (class-of (make-instance 'structure-class-foo1
))
215 (assert (typep (make-instance 'structure-class-foo1
) 'structure-class-foo1
))
216 (assert (typep (class-of (make-instance 'structure-class-foo2
))
218 (assert (typep (make-instance 'structure-class-foo2
) 'structure-class-foo2
)))
220 (defclass standard-class-foo1
() () (:metaclass cl
:standard-class
))
221 (defclass standard-class-foo2
(standard-class-foo1)
222 () (:metaclass cl
:standard-class
))
223 (with-test (:name
(defclass :metaclass cl
:standard-class
))
224 (assert (typep (make-instance 'standard-class-foo1
) 'standard-class-foo1
))
225 (assert (typep (make-instance 'standard-class-foo2
) 'standard-class-foo2
)))
227 ;;; DEFGENERIC's blow-away-old-methods behavior is specified to have
228 ;;; special hacks to distinguish between defined-with-DEFGENERIC-:METHOD
229 ;;; methods and defined-with-DEFMETHOD methods, so that reLOADing
230 ;;; DEFGENERIC-containing files does the right thing instead of
231 ;;; randomly slicing your generic functions. (APD made this work
232 ;;; in sbcl-0.7.0.2.)
233 (defgeneric born-to-be-redefined
(x)
234 (:method
((x integer
))
236 (defmethod born-to-be-redefined ((x real
))
238 (assert (eq (born-to-be-redefined 1) 'integer
))
239 (defgeneric born-to-be-redefined
(x))
240 (assert (eq (born-to-be-redefined 1) 'real
)) ; failed until sbcl-0.7.0.2
241 (defgeneric born-to-be-redefined
(x)
242 (:method
((x integer
))
244 (defmethod born-to-be-redefined ((x integer
))
246 (assert (eq (born-to-be-redefined 1) 'int
))
247 (defgeneric born-to-be-redefined
(x))
248 (assert (eq (born-to-be-redefined 1) 'int
))
250 ;;; In the removal of ITERATE from SB-PCL, a bug was introduced
251 ;;; preventing forward-references and also CHANGE-CLASS (which
252 ;;; forward-references used interally) from working properly.
254 ;;; One symptom was reported by Brian Spilsbury (sbcl-devel
255 ;;; 2002-04-08), and another on IRC by Dan Barlow simultaneously.
256 ;;; Better check that it doesn't happen again.
258 ;;; Some more CHANGE-CLASS testing (which only applies to the now
259 ;;; ANSI-compliant version) thanks to Espen Johnsen)
261 ;; First, the forward references:
262 (defclass forward-ref-a
(forward-ref-b) ())
263 (defclass forward-ref-b
() ())
264 ;; (a couple more complicated examples found by Paul Dietz' test
266 (defclass forward-ref-c1
(forward-ref-c2) ())
267 (defclass forward-ref-c2
(forward-ref-c3) ())
269 (defclass forward-ref-d1
(forward-ref-d2 forward-ref-d3
)
271 (defclass forward-ref-d2
(forward-ref-d4 forward-ref-d5
)
275 (defun change-class-test-case (spec)
276 (destructuring-bind (from-class from-initargs
280 (let ((from (typecase from-class
282 (apply #'make-instance from-class from-initargs
))
283 ((cons (eql :class
) (cons symbol
))
284 (find-class (second from-class
))))))
286 (apply #'change-class from to-class to-initargs
))
287 ;; These local functions make ASSERT produce better error
289 (slot-value-equal (instance name value expected
)
290 (declare (ignore instance name
))
291 (equal value expected
))
292 (slot-not-bound (instance name
)
293 (not (slot-boundp instance name
))))
296 (assert-error (change)))
298 (assert-error (change) type-error
))
301 (loop :for
(name value
) :in expected-slots
304 (assert (slot-not-bound to name
)))
308 to name
(slot-value to name
) value
))))))))))))
310 (defclass change-class.smoke
.1 ()
311 ((foo :initarg
:foo
)))
312 (defclass change-class.smoke
.2 (change-class.smoke
.1) ())
313 (defclass change-class.smoke
.3 (change-class.smoke
.1)
314 ((foo :initarg
:foo
)))
315 (defclass change-class.smoke
.4 ()
316 ((foo :initarg
:foo
) (bar :initarg
:bar
)))
317 (defclass change-class.smoke
.5 ()
318 ((a :initarg
:a
) (b :initarg
:b
) (c :initarg
:c
)))
319 (defclass change-class.smoke
.6 () ())
321 (with-test (:name
(change-class :smoke
))
323 #'change-class-test-case
324 '(;; Test unbound slots.
325 (change-class.smoke
.1 () change-class.smoke
.1 ()
327 (change-class.smoke
.1 () change-class.smoke
.2 ()
329 (change-class.smoke
.1 () change-class.smoke
.3 ()
331 (change-class.smoke
.1 () change-class.smoke
.4 ()
332 ((foo :unbound
) (bar :unbound
)))
333 (change-class.smoke
.4 (:bar
1) change-class.smoke
.1 ()
336 ;; Bound slots are retained.
337 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.1 ()
339 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.2 ()
341 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.3 ()
343 (change-class.smoke
.1 (:foo
:baz
) change-class.smoke
.4 ()
344 ((foo :baz
) (bar :unbound
)))
345 (change-class.smoke
.4 (:foo
:baz
) change-class.smoke
.1 ()
349 (change-class.smoke
.5 (:a
1 :b
2 :c
3) change-class.smoke
.5 ()
352 ;; Original test by Espen Johnsen
353 (change-class.smoke
.1 (:foo
1) change-class.smoke
.4 (:bar
2)
356 ;; Cannot change objects into metaobjects.
357 (change-class.smoke
.6 () class
()
359 (change-class.smoke
.6 () generic-function
()
361 (change-class.smoke
.6 () method
()
363 (change-class.smoke
.6 () slot-definition
()
366 ;; Test for type-checking
368 (locally (declare (optimize (safety 3))) ; force slot type-checking
369 (defclass change-class.type-check
.1 ()
370 ((foo :initarg
:foo
:type real
)))
371 (defclass change-class.type-check
.2 ()
372 ((foo :initarg
:foo
:type integer
))))
374 (with-test (:name
(change-class :type-check
))
376 #'change-class-test-case
377 '(;; These are allowed.
378 (change-class.type-check
.1 () change-class.type-check
.2 ()
380 (change-class.type-check
.1 (:foo
1) change-class.type-check
.2 ()
382 (change-class.type-check
.1 (:foo
1.0) change-class.type-check
.2 (:foo
2)
385 ;; These are not allowed.
386 (change-class.type-check
.1 () change-class.type-check
.2 (:foo
1.0)
388 (change-class.type-check
.1 (:foo
1.0) change-class.type-check
.2 ()
391 ;; Type-mismatches should be recoverable via USE-VALUE restart.
392 (let* ((from (make-instance 'change-class.type-check
.1 :foo
1.0))
393 (to (handler-bind ((type-error (lambda (condition)
394 (declare (ignore condition
))
396 (change-class from
'change-class.type-check
.2))))
397 (assert (equal (slot-value to
'foo
) 3))))
399 ;; Test interaction with initforms and -args
401 (defclass change-class.initforms
.1 ()
403 (defclass change-class.initforms
.2 ()
404 ((foo :initarg
:foo
)))
405 (defclass change-class.initforms
.3 ()
406 ((foo :initarg
:foo
:initform
:bar
)))
407 (defclass change-class.initforms
.4 ()
408 ((foo :initarg
:foo
))
412 (with-test (:name
(change-class :initforms
))
414 #'change-class-test-case
415 '(;; Initialization of added slot.
416 (change-class.initforms
.1 () change-class.initforms
.3 ()
418 (change-class.initforms
.1 () change-class.initforms
.3 (:foo
:fez
)
420 (change-class.initforms
.1 () change-class.initforms
.4 ()
421 ((foo :unbound
))) ; default initargs are not used
422 (change-class.initforms
.1 () change-class.initforms
.4 (:foo
:fez
)
425 ;; Unbound slot remains unbound.
426 (change-class.initforms
.2 () change-class.initforms
.3 ()
428 (change-class.initforms
.2 () change-class.initforms
.3 (:foo
:fez
)
430 (change-class.initforms
.2 () change-class.initforms
.4 ()
432 (change-class.initforms
.2 () change-class.initforms
.4 (:foo
:fez
)
435 ;; Value is retained.
436 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.3 ()
438 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.3 (:foo
:fez
)
440 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.4 ()
442 (change-class.initforms
.2 (:foo
:baz
) change-class.initforms
.4 (:foo
:fez
)
445 ;; Test for FORWARD-REFERENCED-CLASS
447 (defclass change-class.forward-referenced
.1 () ())
448 ;; CHANGE-CLASS.FORWARD-REFERENCED.2 is only needed to create the
449 ;; FORWARD-REFERENCED-CLASS CHANGE-CLASS.FORWARD-REFERENCED.3.
450 (defclass change-class.forward-referenced
.2 (change-class.forward-referenced
.3) ())
452 (with-test (:name
(change-class sb-mop
:forward-referenced-class
))
454 #'change-class-test-case
455 '(;; Changing instances of "ordinary classes" to classes which are
456 ;; instances of FORWARD-REFERENCED-CLASS is not allowed.
457 (change-class.forward-referenced
.1 () change-class.forward-referenced
.3 ()
460 ;; Changing instances of FORWARD-REFERENCED-CLASS into
461 ;; non-CLASSes and in particular non-CLASS metaobjects is not
463 ((:class change-class.forward-referenced
.3) () change-class.forward-referenced
.1 ()
465 ((:class change-class.forward-referenced
.3) () generic-function
()
467 ((:class change-class.forward-referenced
.3) () method
()
469 ((:class change-class.forward-referenced
.3) () slot-definition
()
472 ;; Changing instances of FORWARD-REFERENCED-CLASS into CLASS is
473 ;; allowed but destructive. Therefore has to be final test case.
474 ((:class change-class.forward-referenced
.3) () standard-class
()
477 ;; Test for FUNCALLABLE-STANDARD-CLASS
479 (defclass change-class.funcallable
.1 () ())
480 (defclass change-class.funcallable
.2 () ()
481 (:metaclass sb-mop
:funcallable-standard-class
))
482 (defclass change-class.funcallable
.3 () ()
483 (:metaclass sb-mop
:funcallable-standard-class
))
485 (with-test (:name
(change-class sb-mop
:funcallable-standard-class
))
487 #'change-class-test-case
488 '(;; Cannot change STANDARD-OBJECT into FUNCALLABLE-STANDARD-OBJECT
490 (change-class.funcallable
.1 () change-class.funcallable
.2 ()
492 (change-class.funcallable
.2 () change-class.funcallable
.1 ()
494 ;; FUNCALLABLE-STANDARD-OBJECTs should work.
495 (change-class.funcallable
.2 () change-class.funcallable
.2 ()
497 (change-class.funcallable
.2 () change-class.funcallable
.3 ()
500 ;;; Until Pierre Mai's patch (sbcl-devel 2002-06-18, merged in
501 ;;; sbcl-0.7.4.39) the :MOST-SPECIFIC-LAST option had no effect.
502 (defgeneric bug180
(x)
503 (:method-combination list
:most-specific-last
))
504 (defmethod bug180 list
((x number
))
506 (defmethod bug180 list
((x fixnum
))
508 (assert (equal (bug180 14) '(number fixnum
)))
510 ;;; printing a structure class should not loop indefinitely (or cause
511 ;;; a stack overflow):
512 (defclass test-printing-structure-class
()
513 ((slot :initarg
:slot
))
514 (:metaclass structure-class
))
515 (with-test (:name
:test-printing-structure-class
)
516 (write-to-string (make-instance 'test-printing-structure-class
:slot
2)))
518 ;;; structure-classes should behave nicely when subclassed
519 (defclass super-structure
()
520 ((a :initarg
:a
:accessor a-accessor
)
521 (b :initform
2 :reader b-reader
))
522 (:metaclass structure-class
))
523 (defclass sub-structure
(super-structure)
524 ((c :initarg
:c
:writer c-writer
:accessor c-accessor
))
525 (:metaclass structure-class
))
526 (let ((foo (make-instance 'sub-structure
:a
1 :c
3)))
527 (assert (= (a-accessor foo
) 1))
528 (assert (= (b-reader foo
) 2))
529 (assert (= (c-accessor foo
) 3))
530 (setf (a-accessor foo
) 4)
532 (assert (= (a-accessor foo
) 4))
533 (assert (= (c-accessor foo
) 5)))
535 ;;; At least as of sbcl-0.7.4, PCL has code to support a special
536 ;;; encoding of effective method functions for slot accessors as
537 ;;; FIXNUMs. Given this special casing, it'd be easy for slot accessor
538 ;;; functions to get broken in special ways even though ordinary
539 ;;; generic functions work. As of sbcl-0.7.4 we didn't have any tests
540 ;;; for that possibility. Now we have a few tests:
542 ((fin :reader ffin
:writer ffin
!)
543 (tail :reader ftail
:writer ftail
!)))
544 (defvar *fish
* (make-instance 'fish
))
545 (ffin! 'triangular-fin
*fish
*)
546 (defclass cod
(fish) ())
547 (defvar *cod
* (make-instance 'cod
))
548 (defparameter *clos-dispatch-side-fx
* (make-array 0 :fill-pointer
0))
549 (defmethod ffin! (new-fin (cod cod
))
550 ; (format t "~&about to set ~S fin to ~S~%" cod new-fin)
551 (vector-push-extend '(cod) *clos-dispatch-side-fx
*)
554 ; (format t "~&done setting ~S fin to ~S~%" cod new-fin)
556 (defmethod ffin! :before
(new-fin (cod cod
))
557 (vector-push-extend '(:before cod
) *clos-dispatch-side-fx
*)
558 ;(format t "~&exploring the CLOS dispatch zoo with COD fins~%")
560 (ffin! 'almost-triang-fin
*cod
*)
561 (assert (eq (ffin *cod
*) 'almost-triang-fin
))
562 (assert (equalp #((:before cod
) (cod)) *clos-dispatch-side-fx
*))
564 ;;; Until sbcl-0.7.6.21, the long form of DEFINE-METHOD-COMBINATION
565 ;;; ignored its options; Gerd Moellmann found and fixed the problem
566 ;;; for cmucl (cmucl-imp 2002-06-18).
567 (define-method-combination test-mc
(x)
568 ;; X above being a method-group-specifier
569 ((primary () :required t
))
571 `(call-method ,(first primary
)))
574 (:method-combination test-mc
1))
579 ;;; Until sbcl-0.7.7.20, some conditions weren't being signalled, and
580 ;;; some others were of the wrong type:
581 (macrolet ((assert-program-error (form)
582 `(multiple-value-bind (value error
)
583 (ignore-errors (let ((*error-output
* (make-broadcast-stream)))
585 (unless (and (null value
) (typep error
'program-error
))
586 (error "~S failed: ~S, ~S" ',form value error
)))))
587 (assert-program-error (defclass foo001
() (a b a
)))
588 (assert-program-error (defclass foo002
()
590 (:default-initargs x
'a x
'b
)))
591 (assert-program-error (defclass foo003
()
592 ((a :allocation
:class
:allocation
:class
))))
593 (assert-program-error (defclass foo004
()
595 ;; and some more, found by Wolfhard Buss and fixed for cmucl by Gerd
596 ;; Moellmann in sbcl-0.7.8.x:
597 (assert-program-error (progn
598 (defmethod odd-key-args-checking (&key
(key 42)) key
)
599 (odd-key-args-checking 3)))
600 (assert (= (odd-key-args-checking) 42))
601 (assert (eq (odd-key-args-checking :key t
) t
))
602 ;; yet some more, fixed in sbcl-0.7.9.xx
603 (assert-program-error (defclass foo005
()
604 (:metaclass sb-pcl
::funcallable-standard-class
)
606 (assert-program-error (defclass foo006
()
607 ((a :reader
(setf a
)))))
608 (assert-program-error (defclass foo007
()
610 (assert-program-error (defclass foo008
()
612 (:default-initargs
:a
1)
613 (:default-initargs
:a
2)))
614 ;; and also BUG 47d, fixed in sbcl-0.8alpha.0.26
615 (assert-program-error (defgeneric if
(x)))
616 ;; DEFCLASS should detect an error if slot names aren't suitable as
618 (assert-program-error (defclass foo009
()
620 (assert-program-error (defclass foo010
()
621 (("a" :initarg
:a
))))
622 (assert-program-error (defclass foo011
()
623 ((#1a
() :initarg
:a
))))
624 (assert-program-error (defclass foo012
()
626 (assert-program-error (defclass foo013
() ("a")))
627 ;; specialized lambda lists have certain restrictions on ordering,
628 ;; repeating keywords, and the like:
629 (assert-program-error (defmethod foo014 ((foo t
) &rest
) nil
))
630 (assert-program-error (defmethod foo015 ((foo t
) &rest x y
) nil
))
631 (assert-program-error (defmethod foo016 ((foo t
) &allow-other-keys
) nil
))
632 (assert-program-error (defmethod foo017 ((foo t
)
633 &optional x
&optional y
) nil
))
634 (assert-program-error (defmethod foo018 ((foo t
) &rest x
&rest y
) nil
))
635 (assert-program-error (defmethod foo019 ((foo t
) &rest x
&optional y
) nil
))
636 (assert-program-error (defmethod foo020 ((foo t
) &key x
&optional y
) nil
))
637 (assert-program-error (defmethod foo021 ((foo t
) &key x
&rest y
) nil
)))
639 ;;; DOCUMENTATION's argument-precedence-order wasn't being faithfully
640 ;;; preserved through the bootstrap process until sbcl-0.7.8.39.
641 ;;; (thanks to Gerd Moellmann)
642 (with-test (:name
(documentation :argument-precedence-order
))
646 (let ((answer (documentation 'foo022
'function
)))
647 (assert (stringp answer
))
648 (defmethod documentation ((x (eql 'foo022
)) y
) "WRONG")
649 (assert (string= (documentation 'foo022
'function
) answer
))))
651 ;;; only certain declarations are permitted in DEFGENERIC
652 (macrolet ((assert-program-error (form)
653 `(multiple-value-bind (value error
)
654 (ignore-errors (let ((*error-output
* (make-broadcast-stream)))
656 (assert (null value
))
657 (assert (typep error
'program-error
)))))
658 (assert-program-error (defgeneric bogus-declaration
(x)
659 (declare (special y
))))
660 (assert-program-error (defgeneric bogus-declaration2
(x)
661 (declare (notinline concatenate
)))))
662 ;;; CALL-NEXT-METHOD should call NO-NEXT-METHOD if there is no next
664 (defmethod no-next-method-test ((x integer
)) (call-next-method))
665 (assert-error (no-next-method-test 1) sb-pcl
::no-next-method-error
)
666 (defmethod no-next-method ((g (eql #'no-next-method-test
)) m
&rest args
)
667 (declare (ignore args
))
669 (assert (eq (no-next-method-test 1) 'success
))
670 (assert-error (no-next-method-test 'foo
) sb-pcl
::no-applicable-method-error
)
672 ;;; regression test for bug 176, following a fix that seems
673 ;;; simultaneously to fix 140 while not exposing 176 (by Gerd
674 ;;; Moellmann, merged in sbcl-0.7.9.12).
676 (let ((lastname (intern (format nil
"C176-~D" (1- i
))))
677 (name (intern (format nil
"C176-~D" i
))))
678 (eval `(defclass ,name
679 (,@(if (= i
0) nil
(list lastname
)))
681 (eval `(defmethod initialize-instance :after
((x ,name
) &rest any
)
682 (declare (ignore any
))))))
683 (defclass b176
() (aslot-176))
684 (defclass c176-0
(b176) ())
685 (assert (= 1 (setf (slot-value (make-instance 'c176-9
) 'aslot-176
) 1)))
687 ;;; DEFINE-METHOD-COMBINATION was over-eager at checking for duplicate
689 (define-method-combination dmc-test-mc
(&optional
(order :most-specific-first
))
691 (primary (dmc-test-mc) :order order
:required t
))
692 (let ((form (if (rest primary
)
693 `(and ,@(mapcar #'(lambda (method)
694 `(call-method ,method
))
696 `(call-method ,(first primary
)))))
698 `(call-method ,(first around
)
700 (make-method ,form
)))
703 (defgeneric dmc-test-mc
(&key k
)
704 (:method-combination dmc-test-mc
))
706 (defmethod dmc-test-mc dmc-test-mc
(&key k
)
710 ;;; While I'm at it, DEFINE-METHOD-COMBINATION is defined to return
711 ;;; the NAME argument, not some random method object. So:
712 (assert (eq (define-method-combination dmc-test-return-foo
)
713 'dmc-test-return-foo
))
714 (assert (eq (define-method-combination dmc-test-return-bar
:operator and
)
715 'dmc-test-return-bar
))
716 (assert (eq (define-method-combination dmc-test-return
717 (&optional
(order :most-specific-first
))
719 (primary (dmc-test-return) :order order
:required t
))
720 (let ((form (if (rest primary
)
721 `(and ,@(mapcar #'(lambda (method)
722 `(call-method ,method
))
724 `(call-method ,(first primary
)))))
726 `(call-method ,(first around
)
728 (make-method ,form
)))
732 ;;; DEFINE-METHOD-COMBINATION should, according to the description in 7.7,
733 ;;; allow you to do everything in the body forms yourself if you specify
734 ;;; exactly one method group whose qualifier-pattern is *
736 ;;; The specific language is:
737 ;;; "The use of method group specifiers provides a convenient syntax to select
738 ;;; methods, to divide them among the possible roles, and to perform the
739 ;;; necessary error checking. It is possible to perform further filtering of
740 ;;; methods in the body forms by using normal list-processing operations and
741 ;;; the functions method-qualifiers and invalid-method-error. It is permissible
742 ;;; to use setq on the variables named in the method group specifiers and to
743 ;;; bind additional variables. It is also possible to bypass the method group
744 ;;; specifier mechanism and do everything in the body forms. This is
745 ;;; accomplished by writing a single method group with * as its only
746 ;;; qualifier-pattern; the variable is then bound to a list of all of the
747 ;;; applicable methods, in most-specific-first order."
748 (define-method-combination wam-test-method-combination-a
()
750 (do ((methods all-methods
(rest methods
))
754 (let ((primary (nreverse primary
))
755 (around (nreverse around
)))
757 (let ((form (if (rest primary
)
758 `(call-method ,(first primary
) ,(rest primary
))
759 `(call-method ,(first primary
)))))
761 `(call-method ,(first around
) (,@(rest around
)
762 (make-method ,form
)))
764 `(make-method (error "No primary methods")))))
765 (let* ((method (first methods
))
766 (qualifier (first (method-qualifiers method
))))
768 ((equal :around qualifier
)
769 (push method around
))
771 (push method primary
))))))
773 (defgeneric wam-test-mc-a
(val)
774 (:method-combination wam-test-method-combination-a
))
775 (assert-error (wam-test-mc-a 13))
776 (defmethod wam-test-mc-a ((val number
))
777 (+ val
(if (next-method-p) (call-next-method) 0)))
778 (assert (= (wam-test-mc-a 13) 13))
779 (defmethod wam-test-mc-a :around
((val number
))
780 (+ val
(if (next-method-p) (call-next-method) 0)))
781 (assert (= (wam-test-mc-a 13) 26))
783 ;;; DEFINE-METHOD-COMBINATION
784 ;;; When two methods are in the same method group and have the same
785 ;;; specializers, their sort order within the group may be ambiguous. Therefore,
786 ;;; we should throw an error when we have two methods in the same group with
787 ;;; the same specializers /as long as/ we have more than one method group
788 ;;; or our single method group qualifier-pattern is not *. This resolves the
789 ;;; apparent conflict with the above 'It is also possible to bypass' language.
791 ;;; The language specifying this behavior is:
792 ;;; "Note that two methods with identical specializers, but with different
793 ;;; qualifiers, are not ordered by the algorithm described in Step 2 of the
794 ;;; method selection and combination process described in Section 7.6.6
795 ;;; (Method Selection and Combination). Normally the two methods play different
796 ;;; roles in the effective method because they have different qualifiers, and
797 ;;; no matter how they are ordered in the result of Step 2, the effective
798 ;;; method is the same. If the two methods play the same role and their order
799 ;;; matters, an error is signaled. This happens as part of the qualifier
800 ;;; pattern matching in define-method-combination."
802 ;;; Note that the spec pretty much equates 'method group' and 'role'.
803 ;; First we ensure that it fails correctly when there is more than one
805 (define-method-combination wam-test-method-combination-b
()
807 (primary * :required t
))
808 (let ((form (if (rest primary
)
809 `(call-method ,(first primary
) ,(rest primary
))
810 `(call-method ,(first primary
)))))
812 `(call-method ,(first around
) (,@(rest around
)
813 (make-method ,form
)))
816 (defgeneric wam-test-mc-b
(val)
817 (:method-combination wam-test-method-combination-b
))
818 (defmethod wam-test-mc-b ((val number
))
819 (+ val
(if (next-method-p) (call-next-method) 0)))
820 (assert (= (wam-test-mc-b 13) 13))
821 (defmethod wam-test-mc-b :around
((val number
))
822 (+ val
(if (next-method-p) (call-next-method) 0)))
823 (assert (= (wam-test-mc-b 14) 28))
824 (defmethod wam-test-mc-b :somethingelse
((val number
))
825 (+ val
(if (next-method-p) (call-next-method) 0)))
826 (let ((*error-output
* (make-broadcast-stream)))
827 (assert-error (wam-test-mc-b 15)))
829 ;;; now, ensure that it fails with a single group with a qualifier-pattern
831 (define-method-combination wam-test-method-combination-c
()
832 ((methods listp
:required t
))
834 `(call-method ,(first methods
) ,(rest methods
))
835 `(call-method ,(first methods
))))
837 (defgeneric wam-test-mc-c
(val)
838 (:method-combination wam-test-method-combination-c
))
839 (assert-error (wam-test-mc-c 13))
840 (defmethod wam-test-mc-c :foo
((val number
))
841 (+ val
(if (next-method-p) (call-next-method) 0)))
842 (assert (= (wam-test-mc-c 14) 14))
843 (defmethod wam-test-mc-c :bar
((val number
))
844 (+ val
(if (next-method-p) (call-next-method) 0)))
845 (let ((*error-output
* (make-broadcast-stream)))
846 (assert-error (wam-test-mc-c 15)))
848 ;;; DEFMETHOD should signal an ERROR if an incompatible lambda list is
850 (defmethod incompatible-ll-test-1 (x) x
)
851 (assert-error (defmethod incompatible-ll-test-1 (x y
) y
))
852 (assert-error (defmethod incompatible-ll-test-1 (x &rest y
) y
))
853 ;;; Sneakily using a bit of MOPness to check some consistency
855 (sb-mop:generic-function-methods
#'incompatible-ll-test-1
)) 1))
857 (defmethod incompatible-ll-test-2 (x &key bar
) bar
)
858 (assert-error (defmethod incompatible-ll-test-2 (x) x
))
859 (defmethod incompatible-ll-test-2 (x &rest y
) y
)
861 (sb-mop:generic-function-methods
#'incompatible-ll-test-2
)) 1))
862 (defmethod incompatible-ll-test-2 ((x integer
) &key bar
) bar
)
864 (sb-mop:generic-function-methods
#'incompatible-ll-test-2
)) 2))
866 ;;; Per Christophe, this is an illegal method call because of 7.6.5
867 (handler-bind ((style-warning #'muffle-warning
))
868 (eval '(assert-error (incompatible-ll-test-2 t
1 2))))
870 (assert (eq (incompatible-ll-test-2 1 :bar
'yes
) 'yes
))
872 (defmethod incompatible-ll-test-3 ((x integer
)) x
)
873 (remove-method #'incompatible-ll-test-3
874 (find-method #'incompatible-ll-test-3
876 (list (find-class 'integer
))))
877 (assert-error (defmethod incompatible-ll-test-3 (x y
) (list x y
)))
880 ;;; Attempting to instantiate classes with forward references in their
881 ;;; CPL should signal errors (FIXME: of what type?)
882 (defclass never-finished-class
(this-one-unfinished-too) ())
883 (multiple-value-bind (result error
)
884 (ignore-errors (make-instance 'never-finished-class
))
885 (assert (null result
))
886 (assert (typep error
'error
)))
887 (multiple-value-bind (result error
)
888 (ignore-errors (make-instance 'this-one-unfinished-too
))
889 (assert (null result
))
890 (assert (typep error
'error
)))
892 ;;; Classes with :ALLOCATION :CLASS slots should be subclassable (and
893 ;;; weren't for a while in sbcl-0.7.9.xx)
894 (defclass superclass-with-slot
()
895 ((a :allocation
:class
)))
896 (defclass subclass-for-class-allocation
(superclass-with-slot) ())
897 (make-instance 'subclass-for-class-allocation
)
899 ;;; bug #136: CALL-NEXT-METHOD was being a little too lexical,
900 ;;; resulting in failure in the following:
901 (defmethod call-next-method-lexical-args ((x integer
))
903 (defmethod call-next-method-lexical-args :around
((x integer
))
905 (declare (ignorable x
))
907 (assert (= (call-next-method-lexical-args 3) 3))
909 ;;; DEFINE-METHOD-COMBINATION with arguments was hopelessly broken
911 (defvar *d-m-c-args-test
* nil
)
912 (define-method-combination progn-with-lock
()
916 (progn (lock (object-lock ,object
))
917 ,@(mapcar #'(lambda (method)
918 `(call-method ,method
))
920 (unlock (object-lock ,object
))))
921 (defun object-lock (obj)
922 (push "object-lock" *d-m-c-args-test
*)
925 (push "unlock" *d-m-c-args-test
*)
928 (push "lock" *d-m-c-args-test
*)
930 (defgeneric d-m-c-args-test
(x)
931 (:method-combination progn-with-lock
))
932 (defmethod d-m-c-args-test ((x symbol
))
933 (push "primary" *d-m-c-args-test
*))
934 (defmethod d-m-c-args-test ((x number
))
936 (assert (equal (d-m-c-args-test t
) '("primary" "lock" "object-lock")))
937 (assert (equal *d-m-c-args-test
*
938 '("unlock" "object-lock" "primary" "lock" "object-lock")))
939 (setf *d-m-c-args-test
* nil
)
940 (ignore-errors (d-m-c-args-test 1))
941 (assert (equal *d-m-c-args-test
*
942 '("unlock" "object-lock" "lock" "object-lock")))
944 ;;; The walker (on which DEFMETHOD depended) didn't know how to handle
945 ;;; SYMBOL-MACROLET properly. In fact, as of sbcl-0.7.10.20 it still
946 ;;; doesn't, but it does well enough to compile the following without
947 ;;; error (the problems remain in asking for a complete macroexpansion
948 ;;; of an arbitrary form).
949 (defgeneric bug222
(z))
950 (symbol-macrolet ((x 1))
951 (defmethod bug222 (z)
952 (macrolet ((frob (form) `(progn ,form
,x
)))
953 (frob (princ-to-string x
)))))
954 (assert (= (bug222 t
) 1))
956 ;;; also, a test case to guard against bogus environment hacking:
958 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
960 (defgeneric bug222-b
(z stream
))
961 ;;; this should at the least compile:
963 (defmethod bug222-b (z stream
)
964 (macrolet ((frob (form)
965 ;; This macro's expander should see the global value of BUG222-B.
966 ;; But forcing it do to so by explicit call of SYMBOL-VALUE
967 ;; would defeat the purpose of the test. So ignore the warning.
968 (declare (muffle-conditions warning
))
969 `(progn ,form
,bug222-b
)))
970 (frob (format stream
"~D~%" bug222-b
)))))
971 ;;; and it would be nice (though not specified by ANSI) if the answer
973 (let ((x (make-string-output-stream)))
974 (let ((value (bug222-b t x
)))
975 ;; not specified by ANSI
976 #+#.
(cl:if
(cl:eq sb-ext
:*evaluator-mode
* :compile
) '(and) '(or))
977 (assert (= value
3)))
979 (assert (char= (char (get-output-stream-string x
) 0) #\
1)))
981 ;;; REINITIALIZE-INSTANCE, in the ctor optimization, wasn't checking
982 ;;; for invalid initargs where it should:
983 (defclass class234
() ())
984 (defclass subclass234
(class234) ())
987 (reinitialize-instance (make-instance 'class234
) :dummy
0))
989 (reinitialize-instance (make-instance 'subclass234
) :dummy
0))
990 (assert-error (bug-234) program-error
)
991 (defmethod shared-initialize :after
((i class234
) slots
&key dummy
)
992 (declare (ignore dummy
))
994 (assert (typep (subbug-234) 'subclass234
))
996 ;; once for MAKE-INSTANCE, once for REINITIALIZE-INSTANCE
999 ;;; also, some combinations of MAKE-INSTANCE and subclassing missed
1000 ;;; new methods (Gerd Moellmann sbcl-devel 2002-12-29):
1001 (defclass class234-b1
() ())
1002 (defclass class234-b2
(class234-b1) ())
1003 (defvar *bug234-b
* 0)
1005 (make-instance 'class234-b2
))
1008 (assert (= *bug234-b
* 0))
1009 (defmethod initialize-instance :before
((x class234-b1
) &rest args
)
1010 (declare (ignore args
))
1013 (assert (= *bug234-b
* 1))
1015 ;;; we should be able to make classes with uninterned names:
1016 (defclass #:class-with-uninterned-name
() ())
1018 ;;; SLOT-MISSING should be called when there are missing slots.
1019 (defclass class-with-all-slots-missing
() ())
1020 (defmethod slot-missing (class (o class-with-all-slots-missing
)
1022 &optional new-value
)
1023 (declare (ignore new-value
))
1025 (defmethod cwasm-sv ((o class-with-all-slots-missing
))
1026 (slot-value o
'baz
))
1027 (defmethod cwasm-ssv (nv (o class-with-all-slots-missing
))
1028 (setf (slot-value o
'baz
) nv
))
1029 (defmethod cwasm-sbp ((o class-with-all-slots-missing
))
1030 (slot-boundp o
'baz
))
1031 (defmethod cwasm-smk ((o class-with-all-slots-missing
))
1032 (slot-makunbound o
'baz
))
1034 (with-test (:name
:slot-value-missing
)
1035 (assert (equal (multiple-value-list
1036 (slot-value (make-instance 'class-with-all-slots-missing
) 'foo
))
1038 (assert (equal (multiple-value-list
1039 (funcall (lambda (x) (slot-value x
'bar
))
1040 (make-instance 'class-with-all-slots-missing
)))
1042 (assert (equal (multiple-value-list
1043 (cwasm-sv (make-instance 'class-with-all-slots-missing
)))
1046 (with-test (:name
:slot-boundp-missing
)
1047 (assert (equal (multiple-value-list
1048 (slot-boundp (make-instance 'class-with-all-slots-missing
) 'foo
))
1050 (assert (equal (multiple-value-list
1051 (funcall (lambda (x) (slot-boundp x
'bar
))
1052 (make-instance 'class-with-all-slots-missing
)))
1054 (assert (equal (multiple-value-list
1055 (cwasm-sbp (make-instance 'class-with-all-slots-missing
)))
1058 (with-test (:name
:slot-setf-missing
)
1059 (assert (equal (multiple-value-list
1060 (setf (slot-value (make-instance 'class-with-all-slots-missing
) 'foo
) 10))
1062 (assert (equal (multiple-value-list
1063 (funcall (lambda (x) (setf (slot-value x
'bar
) 20))
1064 (make-instance 'class-with-all-slots-missing
)))
1066 (assert (equal (multiple-value-list
1067 (cwasm-ssv 30 (make-instance 'class-with-all-slots-missing
)))
1070 (with-test (:name
:slot-makunbound-missing
)
1071 (let ((instance (make-instance 'class-with-all-slots-missing
)))
1072 (assert (equal (multiple-value-list (slot-makunbound instance
'foo
))
1074 (assert (equal (multiple-value-list
1075 (funcall (lambda (x) (slot-makunbound x
'bar
)) instance
))
1077 (assert (equal (multiple-value-list
1078 (cwasm-smk instance
))
1081 (macrolet ((try (which)
1082 `(assert (eq ((lambda (x)
1083 (declare (,which sb-pcl
::set-slot-value
))
1084 (setf (slot-value x
'b
) 'baz
))
1085 (make-instance 'class-with-all-slots-missing
))
1086 ;; SLOT-MISSING's value is specified to be ignored; we
1087 ;; return NEW-VALUE.
1092 ;;; we should be able to specialize on anything that names a class.
1093 (defclass name-for-class
() ())
1094 (defmethod something-that-specializes ((x name-for-class
)) 1)
1095 (setf (find-class 'other-name-for-class
) (find-class 'name-for-class
))
1096 (defmethod something-that-specializes ((x other-name-for-class
)) 2)
1097 (assert (= (something-that-specializes (make-instance 'name-for-class
)) 2))
1098 (assert (= (something-that-specializes (make-instance 'other-name-for-class
))
1101 ;;; more forward referenced classes stuff
1102 (defclass frc-1
(frc-2) ())
1103 (assert (subtypep 'frc-1
(find-class 'frc-2
)))
1104 (assert (subtypep (find-class 'frc-1
) 'frc-2
))
1105 (assert (not (subtypep (find-class 'frc-2
) 'frc-1
)))
1106 (defclass frc-2
(frc-3) ((a :initarg
:a
)))
1107 (assert (subtypep 'frc-1
(find-class 'frc-3
)))
1108 (defclass frc-3
() ())
1109 (assert (typep (make-instance 'frc-1
:a
2) (find-class 'frc-1
)))
1110 (assert (typep (make-instance 'frc-2
:a
3) (find-class 'frc-2
)))
1112 ;;; check that we can define classes with two slots of different names
1113 ;;; (even if it STYLE-WARNs).
1114 (defclass odd-name-class
()
1115 ((name :initarg
:name
)
1116 (cl-user::name
:initarg
:name2
)))
1117 (handler-bind ((style-warning #'muffle-warning
))
1118 (let ((x (make-instance 'odd-name-class
:name
1 :name2
2)))
1119 (assert (= (slot-value x
'name
) 1))
1120 (assert (= (slot-value x
'cl-user
::name
) 2))))
1122 ;;; ALLOCATE-INSTANCE should work on structures, even if defined by
1123 ;;; DEFSTRUCT (and not DEFCLASS :METACLASS STRUCTURE-CLASS).
1124 (defstruct allocatable-structure a
)
1125 (assert (typep (allocate-instance (find-class 'allocatable-structure
))
1126 'allocatable-structure
))
1128 ;;; Bug found by Paul Dietz when devising CPL tests: somewhat
1129 ;;; amazingly, calls to CPL would work a couple of times, and then
1130 ;;; start returning NIL. A fix was found (relating to the
1131 ;;; applicability of constant-dfun optimization) by Gerd Moellmann.
1133 (:method-combination list
)
1134 (:method list
((x broadcast-stream
)) 'broadcast-stream
)
1135 (:method list
((x integer
)) 'integer
)
1136 (:method list
((x number
)) 'number
)
1137 (:method list
((x stream
)) 'stream
)
1138 (:method list
((x structure-object
)) 'structure-object
))
1139 (assert (equal (cpl 0) '(integer number
)))
1140 (assert (equal (cpl 0) '(integer number
)))
1141 (assert (equal (cpl 0) '(integer number
)))
1142 (assert (equal (cpl 0) '(integer number
)))
1143 (assert (equal (cpl 0) '(integer number
)))
1144 (assert (equal (cpl (make-broadcast-stream))
1145 '(broadcast-stream stream structure-object
)))
1146 (assert (equal (cpl (make-broadcast-stream))
1147 '(broadcast-stream stream structure-object
)))
1148 (assert (equal (cpl (make-broadcast-stream))
1149 '(broadcast-stream stream structure-object
)))
1151 ;;; Bug in CALL-NEXT-METHOD: assignment to the method's formal
1152 ;;; parameters shouldn't affect the arguments to the next method for a
1153 ;;; no-argument call to CALL-NEXT-METHOD
1154 (defgeneric cnm-assignment
(x)
1156 (:method
((x integer
)) (setq x
3)
1157 (list x
(call-next-method) (call-next-method x
))))
1158 (assert (equal (cnm-assignment 1) '(3 1 3)))
1160 ;;; lp#1734771: Even for assignment to parameters (implcitly or
1161 ;;; explicitly) specialized to T, or using EQL specializers.
1162 (defgeneric bug-1734771
(x y
)
1163 (:method
(x y
) (list x y
))
1164 (:method
((x integer
) y
)
1167 (:method
((x symbol
) (y t
))
1170 (:method
(x (y (eql nil
)))
1172 (opaque-identity y
) ; or else "assigned but never read" style-warning
1173 (call-next-method)))
1174 (with-test (:name
(:cnm-assignment
:bug-1734771
1))
1175 (assert (equal (bug-1734771 2 3) '(2 3))))
1176 (with-test (:name
(:cnm-assignment
:bug-1734771
2))
1177 (assert (equal (bug-1734771 t
3) '(t 3))))
1178 (with-test (:name
(:cnm-assignment
:bug-1734771
3))
1179 (assert (equal (bug-1734771 #\c nil
) '(#\c nil
))))
1181 (defgeneric bug-1734771-2
(x &optional y
)
1182 (:method
(x &optional
(y nil y-p
)) (list x y y-p
))
1183 (:method
((x integer
) &optional
(y 0))
1186 (:method
((x symbol
) &optional
(y 0))
1187 (declare (ignore y
))
1188 (call-next-method)))
1189 (with-test (:name
(:cnm-assignment
:bug-1734771
4))
1190 (assert (equal (bug-1734771-2 2) '(2 nil nil
))))
1191 (with-test (:name
(:cnm-assignment
:bug-1734771
5))
1192 (assert (equal (bug-1734771-2 2 0) '(2 0 t
))))
1193 (with-test (:name
(:cnm-assignment
:bug-1734771
6))
1194 (assert (equal (bug-1734771-2 t
) '(t nil nil
))))
1196 ;;; Bug reported by Istvan Marko 2003-07-09
1197 (let ((class-name (gentemp)))
1198 (loop for i from
1 to
9
1199 for slot-name
= (intern (format nil
"X~D" i
))
1200 for initarg-name
= (intern (format nil
"X~D" i
) :keyword
)
1201 collect
`(,slot-name
:initarg
,initarg-name
) into slot-descs
1202 append
`(,initarg-name
(list 0)) into default-initargs
1203 finally
(eval `(defclass ,class-name
()
1205 (:default-initargs
,@default-initargs
))))
1206 (let ((f (checked-compile `(lambda () (make-instance ',class-name
)))))
1207 (assert (typep (funcall f
) class-name
))))
1209 ;;; bug 262: DEFMETHOD failed on a generic function without a lambda
1211 (ensure-generic-function 'bug262
)
1212 (defmethod bug262 (x y
)
1214 (assert (equal (bug262 1 2) '(1 2)))
1216 ;;; salex on #lisp 2003-10-13 reported that type declarations inside
1217 ;;; WITH-SLOTS are too hairy to be checked
1219 (with-test (:name
(with-slots declare
:note
:hairy
))
1220 (flet ((ensure-no-notes (form)
1221 ;; FIXME: it would be better to check specifically for the "type
1222 ;; is too hairy" note
1223 (checked-compile `(lambda () ,form
) :allow-notes nil
)))
1224 (ensure-no-notes '(with-slots (a) *x
*
1225 (declare (integer a
))
1227 (ensure-no-notes '(with-slots (a) *x
*
1228 (declare (integer a
))
1229 (declare (notinline slot-value
))
1232 ;;; from CLHS 7.6.5.1
1233 (defclass character-class
() ((char :initarg
:char
)))
1234 (defclass picture-class
() ((glyph :initarg
:glyph
)))
1235 (defclass character-picture-class
(character-class picture-class
) ())
1237 (defmethod width ((c character-class
) &key font
) font
)
1238 (defmethod width ((p picture-class
) &key pixel-size
) pixel-size
)
1241 (width (make-instance 'character-class
:char
#\Q
)
1242 :font
'baskerville
:pixel-size
10)
1245 (width (make-instance 'picture-class
:glyph
#\Q
)
1246 :font
'baskerville
:pixel-size
10)
1248 (assert (eq (width (make-instance 'character-picture-class
:char
#\Q
)
1249 :font
'baskerville
:pixel-size
10)
1252 ;;; consequences of 7.6.5.1 on EQL-specialized effective methods
1253 ;;; (reported by Syll, lp#1760987)
1254 (defgeneric eqls1760987
(x &key k1
))
1255 (defmethod eqls1760987 ((x (eql 1)) &key k1 k2
)
1257 (defmethod eqls1760987 ((x (eql 2)) &key k1 k3
)
1259 (defmethod eqls1760987 ((x integer
) &key k1 k4
)
1262 (with-test (:name
:bug-1760987
)
1263 (assert (equal (eqls1760987 1) '(1 nil nil
)))
1264 (assert (equal (eqls1760987 1 :k1
2) '(1 2 nil
)))
1265 (assert (equal (eqls1760987 1 :k2
2) '(1 nil
2)))
1266 (assert (equal (eqls1760987 1 :k1
2 :k2
3) '(1 2 3)))
1267 (assert (equal (eqls1760987 1 :k4
4) '(1 nil nil
)))
1268 (assert (equal (eqls1760987 1 :k1
2 :k4
4) '(1 2 nil
)))
1269 (assert (equal (eqls1760987 1 :k2
2 :k4
4) '(1 nil
2)))
1270 (assert (equal (eqls1760987 1 :k1
2 :k2
3 :k4
4) '(1 2 3)))
1271 (assert (equal (eqls1760987 2) '(2 nil nil
)))
1272 (assert (equal (eqls1760987 2 :k1
2) '(2 2 nil
)))
1273 (assert (equal (eqls1760987 2 :k3
2) '(2 nil
2)))
1274 (assert (equal (eqls1760987 2 :k1
2 :k3
3) '(2 2 3)))
1275 (assert (equal (eqls1760987 2 :k4
4) '(2 nil nil
)))
1276 (assert (equal (eqls1760987 2 :k1
2 :k4
4) '(2 2 nil
)))
1277 (assert (equal (eqls1760987 2 :k3
2 :k4
4) '(2 nil
2)))
1278 (assert (equal (eqls1760987 2 :k1
2 :k3
3 :k4
4) '(2 2 3)))
1279 (assert (equal (eqls1760987 3) '(3 nil nil
)))
1280 (assert (equal (eqls1760987 3 :k1
2) '(3 2 nil
)))
1281 (assert (equal (eqls1760987 3 :k4
2) '(3 nil
2)))
1282 (assert (equal (eqls1760987 3 :k1
2 :k4
3) '(3 2 3)))
1283 (assert-error (eqls1760987 1 :k3
5) program-error
)
1284 (assert-error (eqls1760987 1 :k1
2 :k3
5) program-error
)
1285 (assert-error (eqls1760987 1 :k2
2 :k3
5) program-error
)
1286 (assert-error (eqls1760987 1 :k1
2 :k2
3 :k3
5) program-error
)
1287 (assert-error (eqls1760987 2 :k2
5) program-error
)
1288 (assert-error (eqls1760987 2 :k1
2 :k2
5) program-error
)
1289 (assert-error (eqls1760987 2 :k3
2 :k2
5) program-error
)
1290 (assert-error (eqls1760987 2 :k1
2 :k3
3 :k2
5) program-error
)
1291 (assert-error (eqls1760987 3 :k3
5) program-error
)
1292 (assert-error (eqls1760987 3 :k1
2 :k3
5) program-error
)
1293 (assert-error (eqls1760987 3 :k4
2 :k3
5) program-error
)
1294 (assert-error (eqls1760987 3 :k1
2 :k2
3 :k3
5) program-error
)
1295 (assert-error (eqls1760987 3 :k2
5) program-error
)
1296 (assert-error (eqls1760987 3 :k1
2 :k2
5) program-error
)
1297 (assert-error (eqls1760987 3 :k4
2 :k2
5) program-error
)
1298 (assert-error (eqls1760987 3 :k1
2 :k3
3 :k2
5) program-error
))
1300 ;;; CLHS 7.6.5 should still hold in the presence of auxiliary methods
1301 (defgeneric gf-with-keys-to-check
(a &key b
)
1302 (:method
((a integer
) &key b
) (declare (ignore b
)) (1+ a
))
1303 (:method
((a string
) &key b
) (list a b
))
1304 (:method
((a symbol
) &key b c
) (declare (ignore b
)) (list a c
))
1305 (:method
:around
((a integer
) &key b
) (declare (ignore b
)) (1+ (call-next-method))))
1307 (with-test (:name
(:check-keyword-args
:no-error
))
1308 (assert (= (gf-with-keys-to-check 1) 3))
1309 (assert (= (gf-with-keys-to-check 1 :b
2) 3))
1310 (assert (equal (gf-with-keys-to-check "a") '("a" nil
)))
1311 (assert (equal (gf-with-keys-to-check "a" :b
2) '("a" 2)))
1312 (assert (equal (gf-with-keys-to-check 'a
) '(a nil
)))
1313 (assert (equal (gf-with-keys-to-check 'a
:b
2) '(a nil
)))
1314 (assert (equal (gf-with-keys-to-check 'a
:c
2) '(a 2)))
1315 (assert (equal (gf-with-keys-to-check 'a
:b
2 :c
3) '(a 3))))
1317 (with-test (:name
(:check-keyword-args
:allow-other-keys
:no-error
))
1318 (assert (= (gf-with-keys-to-check 1 :z
3 :allow-other-keys t
) 3))
1319 (assert (= (gf-with-keys-to-check 1 :b
2 :z
3 :allow-other-keys t
) 3))
1320 (assert (equal (gf-with-keys-to-check "a" :z
3 :allow-other-keys t
) '("a" nil
)))
1321 (assert (equal (gf-with-keys-to-check "a" :b
2 :z
3 :allow-other-keys t
) '("a" 2)))
1322 (assert (equal (gf-with-keys-to-check 'a
:z
3 :allow-other-keys t
) '(a nil
)))
1323 (assert (equal (gf-with-keys-to-check 'a
:b
2 :z
3 :allow-other-keys t
) '(a nil
)))
1324 (assert (equal (gf-with-keys-to-check 'a
:c
2 :z
3 :allow-other-keys t
) '(a 2)))
1325 (assert (equal (gf-with-keys-to-check 'a
:b
2 :c
3 :allow-other-keys t
) '(a 3))))
1327 (with-test (:name
(:check-keyword-args
:unmatched-keyword
:error
))
1328 (assert-error (gf-with-keys-to-check 1 :z
3) program-error
)
1329 (assert-error (gf-with-keys-to-check 1 :b
2 :z
3) program-error
)
1330 (assert-error (gf-with-keys-to-check "a" :z
3) program-error
)
1331 (assert-error (gf-with-keys-to-check "a" :b
2 :z
3) program-error
)
1332 (assert-error (gf-with-keys-to-check 'a
:z
3) program-error
)
1333 (assert-error (gf-with-keys-to-check 'a
:b
2 :z
3) program-error
)
1334 (assert-error (gf-with-keys-to-check 'a
:c
2 :z
3) program-error
)
1335 (assert-error (gf-with-keys-to-check 'a
:b
2 :c
3 :z
4) program-error
))
1337 (with-test (:name
(:check-keyword-args
:odd-keyword
:error
))
1338 (assert-error (gf-with-keys-to-check 1 :b
) program-error
)
1339 (assert-error (gf-with-keys-to-check 1 :b
2 :b
) program-error
)
1340 (assert-error (gf-with-keys-to-check "a" :b
) program-error
)
1341 (assert-error (gf-with-keys-to-check "a" :b
2 :b
) program-error
)
1342 (assert-error (gf-with-keys-to-check 'a
:b
) program-error
)
1343 (assert-error (gf-with-keys-to-check 'a
:b
2 :b
) program-error
)
1344 (assert-error (gf-with-keys-to-check 'a
:c
2 :b
) program-error
)
1345 (assert-error (gf-with-keys-to-check 'a
:b
2 :c
3 :b
) program-error
))
1347 ;;; verify that we perform these checks for standardized generic
1349 (defclass shared-initialize-keyword-check
() ())
1351 (with-test (:name
(:check-keyword-args shared-initialize
:odd-keyword
:error
))
1352 (assert-error (shared-initialize (make-instance 'shared-initialize-keyword-check
) nil
:a
)
1355 (with-test (:name
(:check-keyword-args shared-initialize
:non-keyword
:error
))
1356 (assert-error (shared-initialize (make-instance 'shared-initialize-keyword-check
) nil
'(abc) 1)
1359 ;;; verify that we can still detect no primary methods and invalid qualifiers
1361 (defmethod gf-with-keys-and-no-primary-method :around
((x integer
) &key b
)
1362 (declare (ignore b
))
1365 (with-test (:name
(:check-keyword-args
:no-primary-method
:no-keywords
:error
))
1366 (assert-error (gf-with-keys-and-no-primary-method 3) sb-pcl
::no-primary-method-error
))
1367 (with-test (:name
(:check-keyword-args
:no-primary-method
:ok-keyword
:error
))
1368 (assert-error (gf-with-keys-and-no-primary-method 3 :b
2) sb-pcl
::no-primary-method-error
))
1369 (with-test (:name
(:check-keyword-args
:no-primary-method
:bad-keyword
:error
))
1370 (assert-error (gf-with-keys-and-no-primary-method 3 :c
2)
1371 (or program-error sb-pcl
::no-primary-method-error
)))
1373 (defgeneric gf-with-keys-and-invalid-qualifier
(x &key
)
1374 (:method-combination progn
))
1375 (defmethod gf-with-keys-and-invalid-qualifier progn
((x integer
) &key b
)
1376 (declare (ignore b
))
1377 (print (1+ x
) (make-broadcast-stream))) ; don't show noise
1378 ;; I'm guessing this is PROGN but spelled wrong purposely, right?
1379 (defmethod gf-with-keys-and-invalid-qualifier prong
((x fixnum
) &key c
) (print c
))
1381 (with-test (:name
(:check-keyword-args
:invalid-qualifier
:no-keywords
:error
))
1382 (assert-error (gf-with-keys-and-invalid-qualifier 3)))
1383 (with-test (:name
(:check-keyword-args
:invalid-qualifier
:ok-keyword
:error
))
1384 (assert-error (gf-with-keys-and-invalid-qualifier 3 :b
3)))
1385 (with-test (:name
(:check-keyword-args
:invalid-qualifier
:bad-keyword
:error
))
1386 (assert-error (gf-with-keys-and-invalid-qualifier 3 :z
4)))
1387 (with-test (:name
(:check-keyword-args
:no-applicable-invalid-qualifier
:no-keywords
:no-error
))
1388 (assert (= (gf-with-keys-and-invalid-qualifier (1+ most-positive-fixnum
))
1389 (+ most-positive-fixnum
2))))
1390 (with-test (:name
(:check-keyword-args
:no-applicable-invalid-qualifier
:ok-keyword
:no-error
))
1391 (assert (= (gf-with-keys-and-invalid-qualifier (1+ most-positive-fixnum
) :b
3)
1392 (+ most-positive-fixnum
2))))
1393 (with-test (:name
(:check-keyword-args
:no-applicable-invalid-qualifier
:bad-keyword
:error
))
1394 (assert-error (gf-with-keys-and-invalid-qualifier (1+ most-positive-fixnum
) :c
3)))
1396 ;;; class redefinition shouldn't give any warnings, in the usual case
1397 (defclass about-to-be-redefined
() ((some-slot :accessor some-slot
)))
1398 (handler-bind ((warning #'error
))
1399 (defclass about-to-be-redefined
() ((some-slot :accessor some-slot
))))
1401 ;;; attempts to add accessorish methods to generic functions with more
1402 ;;; complex lambda lists should fail
1403 (defgeneric accessoroid
(object &key
&allow-other-keys
))
1405 (defclass accessoroid-class
() ((slot :accessor accessoroid
)))
1408 ;;; reported by Bruno Haible sbcl-devel 2004-04-15
1409 (defclass shared-slot-and-redefinition
()
1410 ((size :initarg
:size
:initform
1 :allocation
:class
)))
1411 (let ((i (make-instance 'shared-slot-and-redefinition
)))
1412 (defclass shared-slot-and-redefinition
()
1413 ((size :initarg
:size
:initform
2 :allocation
:class
)))
1414 (assert (= (slot-value i
'size
) 1)))
1416 ;;; reported by Bruno Haible sbcl-devel 2004-04-15
1417 (defclass superclass-born-to-be-obsoleted
() (a))
1418 (defclass subclass-born-to-be-obsoleted
(superclass-born-to-be-obsoleted) ())
1419 (defparameter *born-to-be-obsoleted
*
1420 (make-instance 'subclass-born-to-be-obsoleted
))
1421 (defparameter *born-to-be-obsoleted-obsoleted
* nil
)
1422 (defmethod update-instance-for-redefined-class
1423 ((o subclass-born-to-be-obsoleted
) a d pl
&key
)
1424 (setf *born-to-be-obsoleted-obsoleted
* t
))
1425 (make-instances-obsolete 'superclass-born-to-be-obsoleted
)
1426 (slot-boundp *born-to-be-obsoleted
* 'a
)
1427 (assert *born-to-be-obsoleted-obsoleted
*)
1429 ;;; additional test suggested by Bruno Haible sbcl-devel 2004-04-21
1430 (defclass super-super-obsoleted
() (a))
1431 (defclass super-obsoleted-1
(super-super-obsoleted) ())
1432 (defclass super-obsoleted-2
(super-super-obsoleted) ())
1433 (defclass obsoleted
(super-obsoleted-1 super-obsoleted-2
) ())
1434 (defparameter *obsoleted
* (make-instance 'obsoleted
))
1435 (defparameter *obsoleted-counter
* 0)
1436 (defmethod update-instance-for-redefined-class ((o obsoleted
) a d pl
&key
)
1437 (incf *obsoleted-counter
*))
1438 (make-instances-obsolete 'super-super-obsoleted
)
1439 (slot-boundp *obsoleted
* 'a
)
1440 (assert (= *obsoleted-counter
* 1))
1442 ;;; yet another MAKE-INSTANCES-OBSOLETE test, this time from Nikodemus
1443 ;;; Siivola. Not all methods for accessing slots are created equal...
1444 (defclass yet-another-obsoletion-super
() ((obs :accessor obs-of
:initform
0)))
1445 (defclass yet-another-obsoletion-sub
(yet-another-obsoletion-super) ())
1446 (defmethod shared-initialize :after
((i yet-another-obsoletion-super
)
1448 (declare (ignore init
))
1451 (defvar *yao-super
* (make-instance 'yet-another-obsoletion-super
))
1452 (defvar *yao-sub
* (make-instance 'yet-another-obsoletion-sub
))
1454 (assert (= (obs-of *yao-super
*) 1))
1455 (assert (= (obs-of *yao-sub
*) 1))
1456 (make-instances-obsolete 'yet-another-obsoletion-super
)
1457 (assert (= (obs-of *yao-sub
*) 2))
1458 (assert (= (obs-of *yao-super
*) 2))
1459 (make-instances-obsolete 'yet-another-obsoletion-super
)
1460 (assert (= (obs-of *yao-super
*) 3))
1461 (assert (= (obs-of *yao-sub
*) 3))
1462 (assert (= (slot-value *yao-super
* 'obs
) 3))
1463 (assert (= (slot-value *yao-sub
* 'obs
) 3))
1465 ;;; one more MIO test: variable slot names
1466 (defclass mio
() ((x :initform
42)))
1467 (defvar *mio-slot
* 'x
)
1468 (defparameter *mio-counter
* 0)
1469 (defmethod update-instance-for-redefined-class ((instance mio
) new old plist
&key
)
1470 (incf *mio-counter
*))
1472 (let ((x (make-instance 'mio
)))
1473 (make-instances-obsolete 'mio
)
1474 (slot-value x
*mio-slot
*))
1476 (let ((x (make-instance 'mio
)))
1477 (make-instances-obsolete 'mio
)
1478 (setf (slot-value x
*mio-slot
*) 13))
1480 (let ((x (make-instance 'mio
)))
1481 (make-instances-obsolete 'mio
)
1482 (slot-boundp x
*mio-slot
*))
1484 (let ((x (make-instance 'mio
)))
1485 (make-instances-obsolete 'mio
)
1486 (slot-makunbound x
*mio-slot
*))
1488 (assert (= 4 *mio-counter
*))
1490 ;;; :class -> :instance slot allocation transfers of inherited slots,
1491 ;;; reported by Bruno Haible
1492 (with-test (:name
(defclass :redefinition-class-
>instance-allocation
))
1494 (defclass super-with-magic-slot
()
1495 ((magic :initarg
:size
:initform
1 :allocation
:class
)))
1496 (defclass sub-of-super-with-magic-slot
(super-with-magic-slot) ())
1497 (setq i
(make-instance 'sub-of-super-with-magic-slot
))
1498 (defclass super-with-magic-slot
()
1499 ((magic :initarg
:size
:initform
2)))
1500 (assert (= 1 (slot-value i
'magic
)))))
1502 ;;; MAKE-INSTANCES-OBSOLETE return values
1503 (with-test (:name
(make-instances-obsolete :return-values
) )
1504 (defclass one-more-to-obsolete
() ())
1505 (assert (eq 'one-more-to-obsolete
1506 (make-instances-obsolete 'one-more-to-obsolete
)))
1507 (assert (eq (find-class 'one-more-to-obsolete
)
1508 (make-instances-obsolete (find-class 'one-more-to-obsolete
)))))
1510 ;;; Sensible error instead of a BUG. Reported by Thomas Burdick.
1511 (with-test (:name
(defclass :slot-with-duplicate-accessors
))
1512 (assert-error (defclass slot-with-duplicate-accessors
()
1513 ((slot :writer get-slot
:reader get-slot
)))
1514 (and error
(not sb-int
:bug
))))
1516 ;;; BUG 321: errors in parsing DEFINE-METHOD-COMBINATION arguments
1519 (define-method-combination w-args
()
1521 (:arguments arg1 arg2
&aux
(extra :extra
))
1522 `(progn ,arg1
,arg2
,extra
1523 ,@(mapcar (lambda (method) `(call-method ,method
)) method-list
)))
1524 (defgeneric mc-test-w-args
(p1 p2 s
)
1525 (:method-combination w-args
)
1526 (:method
((p1 number
) (p2 t
) s
)
1527 (vector-push-extend (list 'number p1 p2
) s
))
1528 (:method
((p1 string
) (p2 t
) s
)
1529 (vector-push-extend (list 'string p1 p2
) s
))
1530 (:method
((p1 t
) (p2 t
) s
) (vector-push-extend (list t p1 p2
) s
)))
1531 (let ((v (make-array 0 :adjustable t
:fill-pointer t
)))
1532 (assert (= (mc-test-w-args 1 2 v
) 1))
1533 (assert (equal (aref v
0) '(number 1 2)))
1534 (assert (equal (aref v
1) '(t 1 2))))
1536 ;;; BUG 276: declarations and mutation.
1537 (defmethod fee ((x fixnum
))
1540 (assert (= (fee 1) 1/2))
1541 (defmethod fum ((x fixnum
))
1544 (assert (= (fum 3) 3/2))
1545 (defmethod fii ((x fixnum
))
1546 (declare (special x
))
1549 (assert (= (fii 1) 1/2))
1551 (defmethod faa ((*faa
* string-stream
))
1552 (setq *faa
* (make-broadcast-stream *faa
*))
1553 (write-line "Break, you sucker!" *faa
*)
1555 (assert (eq 'ok
(faa (make-string-output-stream))))
1556 (defmethod fex ((x fixnum
) (y fixnum
))
1557 (multiple-value-setq (x y
) (values (/ x y
) (/ y x
)))
1559 (assert (equal (fex 5 3) '(5/3 3/5)))
1561 ;;; Bug reported by Zach Beane; incorrect return of (function
1562 ;;; ',fun-name) in defgeneric
1563 (with-test (:name
(defgeneric :return type
))
1565 (let ((fun (checked-compile form
)))
1566 (assert (typep (funcall fun
) 'generic-function
)))))
1567 (test '(lambda () (flet ((nonsense () nil
))
1568 (declare (ignorable #'nonsense
))
1569 (defgeneric nonsense
()))))
1570 (test '(lambda () (flet ((nonsense-2 () nil
))
1571 (declare (ignorable #'nonsense-2
))
1572 (defgeneric nonsense-2
()
1573 (:method
() t
)))))))
1575 ;;; bug reported by Bruno Haible: (setf find-class) using a
1576 ;;; forward-referenced class
1577 (defclass fr-sub
(fr-super) ())
1578 (setf (find-class 'fr-alt
) (find-class 'fr-super
))
1579 (assert (eq (find-class 'fr-alt
) (find-class 'fr-super
)))
1582 ;;; ANSI Figure 4-8: all defined classes. Check that we can define
1583 ;;; methods on all of these.
1585 (defgeneric method-for-defined-classes
(x))
1586 (dolist (c '(arithmetic-error
1587 generic-function simple-error array hash-table
1589 bit-vector integer simple-warning
1590 broadcast-stream list standard-class
1591 built-in-class logical-pathname standard-generic-function
1592 cell-error method standard-method
1593 character method-combination standard-object
1594 class null storage-condition
1595 complex number stream
1596 concatenated-stream package stream-error
1597 condition package-error string
1598 cons parse-error string-stream
1599 control-error pathname structure-class
1600 division-by-zero print-not-readable structure-object
1601 echo-stream program-error style-warning
1602 end-of-file random-state symbol
1603 error ratio synonym-stream
1604 file-error rational t
1605 file-stream reader-error two-way-stream
1606 float readtable type-error
1607 floating-point-inexact real unbound-slot
1608 floating-point-invalid-operation restart unbound-variable
1609 floating-point-overflow sequence undefined-function
1610 floating-point-underflow serious-condition vector
1611 function simple-condition warning
))
1612 (eval `(defmethod method-for-defined-classes ((x ,c
)) (princ x
))))
1613 (assert (string= (with-output-to-string (*standard-output
*)
1614 (method-for-defined-classes #\
3))
1619 ;;; When class definition does not complete due to a bad accessor
1620 ;;; name, do not cause an error when a new accessor name is provided
1621 ;;; during class redefinition
1623 (defun existing-name (object)
1626 (assert-error (defclass redefinition-of-accessor-class
()
1627 ((slot :accessor existing-name
))))
1629 (defclass redefinition-of-accessor-class
()
1630 ((slot :accessor new-name
)))
1634 (load "package-ctor-bug.lisp")
1635 (assert (= (package-ctor-bug:test
) 3))
1636 (delete-package "PACKAGE-CTOR-BUG")
1637 (load "package-ctor-bug.lisp")
1638 (assert (= (package-ctor-bug:test
) 3))
1640 (with-test (:name
(defmethod (setf find-class
) integer
))
1641 (handler-bind ((warning #'muffle-warning
))
1644 (deftype defined-type
() 'integer
)
1646 (defmethod method-on-defined-type ((x defined-type
)) x
))
1647 (deftype defined-type-and-class
() 'integer
)
1648 (setf (find-class 'defined-type-and-class
) (find-class 'integer
))
1649 (defmethod method-on-defined-type-and-class
1650 ((x defined-type-and-class
))
1652 (assert (= (method-on-defined-type-and-class 3) 4))))))
1655 (let (#+nil
; no more sb-pcl::*max-emf-precomputation-methods* as of
1657 (sb-pcl::*max-emf-precomputation-methods
* 0))
1658 (handler-bind ((warning #'muffle-warning
)) ; "invalid qualifiers"
1659 (eval '(defgeneric bug-281
(x)
1660 (:method-combination
+)
1661 (:method
((x symbol
)) 1)
1662 (:method
+ ((x number
)) x
))))
1663 (assert (= 1 (funcall 'bug-281
1)))
1664 (assert (= 4.2 (funcall 'bug-281
4.2)))
1665 (multiple-value-bind (val err
) (ignore-errors (funcall 'bug-281
'symbol
))
1667 (assert (typep err
'error
))))
1669 ;;; RESTART-CASE and CALL-METHOD
1671 ;;; from Bruno Haible
1673 (defun rc-cm/prompt-for-new-values
()
1674 (format *debug-io
* "~&New values: ")
1675 (finish-output *debug-io
*)
1676 (list (read *debug-io
*)))
1678 (defun rc-cm/add-method-restarts
(form method
)
1679 (let ((block (gensym))
1687 :report
(lambda (stream)
1688 (format stream
"Try calling ~S again." ,method
))
1691 :report
(lambda (stream)
1692 (format stream
"Specify return values for ~S call."
1694 :interactive
(lambda () (rc-cm/prompt-for-new-values
))
1695 (return-from ,block
(values-list l
)))))))))
1697 (defun rc-cm/convert-effective-method
(efm)
1699 (if (eq (car efm
) 'call-method
)
1700 (let ((method-list (third efm
)))
1701 (if (or (typep (first method-list
) 'method
) (rest method-list
))
1702 ;; Reduce the case of multiple methods to a single one.
1703 ;; Make the call to the next-method explicit.
1704 (rc-cm/convert-effective-method
1705 `(call-method ,(second efm
)
1707 (call-method ,(first method-list
) ,(rest method-list
))))))
1708 ;; Now the case of at most one method.
1709 (if (typep (second efm
) 'method
)
1710 ;; Wrap the method call in a RESTART-CASE.
1711 (rc-cm/add-method-restarts
1712 (cons (rc-cm/convert-effective-method
(car efm
))
1713 (rc-cm/convert-effective-method
(cdr efm
)))
1715 ;; Normal recursive processing.
1716 (cons (rc-cm/convert-effective-method
(car efm
))
1717 (rc-cm/convert-effective-method
(cdr efm
))))))
1718 (cons (rc-cm/convert-effective-method
(car efm
))
1719 (rc-cm/convert-effective-method
(cdr efm
))))
1722 (define-method-combination standard-with-restarts
()
1725 (primary () :required t
)
1727 (flet ((call-methods-sequentially (methods)
1728 (mapcar #'(lambda (method)
1729 `(call-method ,method
))
1731 (let ((form (if (or before after
(rest primary
))
1732 `(multiple-value-prog1
1734 ,@(call-methods-sequentially before
)
1735 (call-method ,(first primary
) ,(rest primary
)))
1736 ,@(call-methods-sequentially (reverse after
)))
1737 `(call-method ,(first primary
)))))
1740 `(call-method ,(first around
)
1741 (,@(rest around
) (make-method ,form
)))))
1742 (rc-cm/convert-effective-method form
))))
1744 (defgeneric rc-cm
/testgf16
(x)
1745 (:method-combination standard-with-restarts
))
1746 (defclass rc-cm
/testclass16a
() ())
1747 (defclass rc-cm
/testclass16b
(rc-cm/testclass16a
) ())
1748 (defclass rc-cm
/testclass16c
(rc-cm/testclass16a
) ())
1749 (defclass rc-cm
/testclass16d
(rc-cm/testclass16b rc-cm
/testclass16c
) ())
1750 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16a
))
1752 (not (null (find-restart 'method-redo
)))
1753 (not (null (find-restart 'method-return
)))))
1754 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16b
))
1755 (cons 'b
(call-next-method)))
1756 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16c
))
1757 (cons 'c
(call-next-method)))
1758 (defmethod rc-cm/testgf16
((x rc-cm
/testclass16d
))
1759 (cons 'd
(call-next-method)))
1760 (assert (equal (rc-cm/testgf16
(make-instance 'rc-cm
/testclass16d
))
1763 ;;; test case from Gerd Moellmann
1764 (define-method-combination r-c
/c-m-1
()
1765 ((primary () :required t
))
1766 `(restart-case (call-method ,(first primary
))))
1768 (defgeneric r-c
/c-m-1-gf
()
1769 (:method-combination r-c
/c-m-1
)
1772 (assert (null (r-c/c-m-1-gf
)))
1774 (handler-bind ((warning #'error
))
1775 (eval '(defclass class-for-ctor
/class-slot
()
1776 ((class-slot :initarg
:class-slot
:allocation
:class
))))
1777 (eval '(let ((c1 (make-instance 'class-for-ctor
/class-slot
))
1778 (c2 (make-instance 'class-for-ctor
/class-slot
:class-slot
1)))
1779 (assert (equal (list (slot-value c1
'class-slot
)
1780 (slot-value c2
'class-slot
))
1783 ;;; tests of ctors on anonymous classes
1784 (defparameter *unnamed
* (defclass ctor-unnamed-literal-class
() ()))
1785 (setf (class-name *unnamed
*) nil
)
1786 (setf (find-class 'ctor-unnamed-literal-class
) nil
)
1787 (defparameter *unnamed2
* (defclass ctor-unnamed-literal-class2
() ()))
1788 (defun ctor-unnamed-literal-class ()
1789 (make-instance '#.
*unnamed
*))
1790 (compile 'ctor-unnamed-literal-class
)
1791 (defun ctor-unnamed-literal-class2 ()
1792 (make-instance '#.
(find-class 'ctor-unnamed-literal-class2
)))
1793 (compile 'ctor-unnamed-literal-class2
)
1794 (defun ctor-unnamed-literal-class2/symbol
()
1795 (make-instance 'ctor-unnamed-literal-class2
))
1796 (compile 'ctor-unnamed-literal-class2
/symbol
)
1797 (setf (class-name *unnamed2
*) nil
)
1798 (setf (find-class 'ctor-unnamed-literal-class2
) nil
)
1799 (with-test (:name
(:ctor
:unnamed-before
))
1800 (assert (typep (ctor-unnamed-literal-class) *unnamed
*)))
1801 (with-test (:name
(:ctor
:unnamed-after
))
1802 (assert (typep (ctor-unnamed-literal-class2) *unnamed2
*)))
1803 (with-test (:name
(:ctor
:unnamed-after
/symbol
))
1804 (assert-error (ctor-unnamed-literal-class2/symbol
)))
1806 ;;; classes with slot types shouldn't break if the types don't name
1807 ;;; classes (bug #391)
1808 (defclass slot-type-superclass
() ((slot :type fixnum
)))
1809 (defclass slot-type-subclass
(slot-type-superclass)
1810 ((slot :type
(integer 1 5))))
1811 (let ((instance (make-instance 'slot-type-subclass
)))
1812 (setf (slot-value instance
'slot
) 3))
1814 ;;; ctors where there's a non-standard SHARED-INITIALIZE method and an
1815 ;;; initarg which isn't self-evaluating (kpreid on #lisp 2006-01-29)
1816 (defclass kpreid-enode
()
1817 ((slot :initarg not-a-keyword
)))
1818 (defmethod shared-initialize ((o kpreid-enode
) slots
&key
&allow-other-keys
)
1820 (defun make-kpreid-enode ()
1821 (make-instance 'kpreid-enode
'not-a-keyword
3))
1822 (with-test (:name
(:ctor
:non-keyword-initarg
))
1823 (let ((x (make-kpreid-enode))
1824 (y (make-kpreid-enode)))
1825 (= (slot-value x
'slot
) (slot-value y
'slot
))))
1827 ;;; defining a class hierarchy shouldn't lead to spurious classoid
1828 ;;; errors on TYPEP questions (reported by Tim Moore on #lisp
1830 (defclass backwards-2
(backwards-1) (a b
))
1831 (defclass backwards-3
(backwards-2) ())
1832 (defun typep-backwards-3 (x)
1833 (typep x
'backwards-3
))
1834 (defclass backwards-1
() (a b
))
1835 (assert (not (typep-backwards-3 1)))
1836 (assert (not (typep-backwards-3 (make-instance 'backwards-2
))))
1837 (assert (typep-backwards-3 (make-instance 'backwards-3
)))
1839 (defgeneric remove-method-1
(x)
1840 (:method
((x integer
)) (1+ x
)))
1841 (defgeneric remove-method-2
(x)
1842 (:method
((x integer
)) (1- x
)))
1843 (assert (eq #'remove-method-1
1844 (remove-method #'remove-method-1
1845 (find-method #'remove-method-2
1847 (list (find-class 'integer
))))))
1848 (assert (= (remove-method-1 3) 4))
1849 (assert (= (remove-method-2 3) 2))
1851 ;;; ANSI doesn't require these restarts, but now that we have them we
1852 ;;; better test them too.
1853 (defclass slot-unbound-restart-test
() ((x)))
1854 (let ((test (make-instance 'slot-unbound-restart-test
)))
1855 (assert (not (slot-boundp test
'x
)))
1856 (assert (= 42 (handler-bind ((unbound-slot (lambda (c) (use-value 42 c
))))
1857 (slot-value test
'x
))))
1858 (assert (not (slot-boundp test
'x
)))
1859 (assert (= 13 (handler-bind ((unbound-slot (lambda (c) (store-value 13 c
))))
1860 (slot-value test
'x
))))
1861 (assert (= 13 (slot-value test
'x
))))
1862 ;;; Using class instances as specializers, reported by Pascal Costanza, ref CLHS 7.6.2
1863 (defclass class-as-specializer-test
()
1865 (eval `(defmethod class-as-specializer-test1 ((x ,(find-class 'class-as-specializer-test
)))
1867 (assert (eq 'foo
(class-as-specializer-test1 (make-instance 'class-as-specializer-test
))))
1868 (funcall (checked-compile `(lambda ()
1869 (defmethod class-as-specializer-test2 ((x ,(find-class 'class-as-specializer-test
)))
1871 (assert (eq 'bar
(class-as-specializer-test2 (make-instance 'class-as-specializer-test
))))
1873 ;;; CHANGE-CLASS and tricky allocation.
1874 (defclass foo-to-be-changed
()
1875 ((a :allocation
:class
:initform
1)))
1876 (defclass bar-to-be-changed
(foo-to-be-changed) ())
1877 (defvar *bar-to-be-changed
* (make-instance 'bar-to-be-changed
))
1878 (defclass baz-to-be-changed
()
1879 ((a :allocation
:instance
:initform
2)))
1880 (change-class *bar-to-be-changed
* 'baz-to-be-changed
)
1881 (assert (= (slot-value *bar-to-be-changed
* 'a
) 1))
1883 ;;; proper name and class redefinition
1884 (defvar *to-be-renamed1
* (defclass to-be-renamed1
() ()))
1885 (defvar *to-be-renamed2
* (defclass to-be-renamed2
() ()))
1886 (setf (find-class 'to-be-renamed1
) (find-class 'to-be-renamed2
))
1887 (defvar *renamed1
* (defclass to-be-renamed1
() ()))
1888 (assert (not (eq *to-be-renamed1
* *to-be-renamed2
*)))
1889 (assert (not (eq *to-be-renamed1
* *renamed1
*)))
1890 (assert (not (eq *to-be-renamed2
* *renamed1
*)))
1892 ;;; CLASS-NAME (and various other standardized generic functions) have
1893 ;;; their effective methods precomputed; in the process of rearranging
1894 ;;; (SETF FIND-CLASS) and FINALIZE-INHERITANCE, this broke.
1895 (defclass class-with-odd-class-name-method
()
1896 ((a :accessor class-name
)))
1898 ;;; another case where precomputing (this time on PRINT-OBJECT) and
1899 ;;; lazily-finalized classes caused problems. (report from James Y
1900 ;;; Knight sbcl-devel 20-07-2006)
1902 (defclass base-print-object
() ())
1903 ;;; this has the side-effect of finalizing BASE-PRINT-OBJECT, and
1904 ;;; additionally the second specializer (STREAM) changes the cache
1905 ;;; structure to require two keys, not just one.
1906 ;; warning is "Specializing on the second argument to PRINT-OBJECT ..."
1907 (handler-bind ((warning #'muffle-warning
))
1908 (defmethod print-object ((o base-print-object
) (s stream
))
1910 ;;; unfinalized as yet
1911 (defclass sub-print-object
(base-print-object) ())
1912 ;;; the accessor causes an eager finalization
1913 (defclass subsub-print-object
(sub-print-object)
1916 ;;; triggers a discriminating function (and so cache) recomputation.
1917 ;;; The method on BASE-PRINT-OBJECT will cause the system to attempt
1918 ;;; to fill the cache for all subclasses of BASE-PRINT-OBJECT which
1919 ;;; have valid wrappers; however, in the course of doing so, the
1920 ;;; SUB-PRINT-OBJECT class gets finalized, which invalidates the
1921 ;;; SUBSUB-PRINT-OBJECT wrapper; if an invalid wrapper gets into a
1922 ;;; cache with more than one key, then failure ensues.
1923 (reinitialize-instance #'print-object
)
1925 ;;; bug in long-form method combination: if there's an applicable
1926 ;;; method not part of any method group, we need to call
1927 ;;; INVALID-METHOD-ERROR. (MC27 test case from Bruno Haible)
1928 (define-method-combination mc27
()
1930 (ignored (:ignore
:unused
)))
1932 ,@(mapcar #'(lambda (method) `(call-method ,method
)) normal
)))
1933 (defgeneric test-mc27
(x)
1934 (:method-combination mc27
)
1935 (:method
:ignore
((x number
)) (declare (notinline /)) (/ 0)))
1936 (handler-bind ((style-warning #'muffle-warning
))
1937 (assert-error (test-mc27 7)))
1939 (define-method-combination mc27prime
()
1941 (ignored (:ignore
)))
1942 `(list 'result
,@(mapcar (lambda (m) `(call-method ,m
)) normal
)))
1943 (defgeneric test-mc27prime
(x)
1944 (:method-combination mc27prime
)
1945 (:method
:ignore
((x number
)) (declare (notinline /)) (/ 0)))
1946 (handler-bind ((style-warning #'muffle-warning
))
1947 (assert (equal '(result) (test-mc27prime 3))))
1948 (assert-error (test-mc27 t
) sb-pcl
::no-applicable-method-error
) ; still no-applicable-method
1950 ;;; more invalid wrappers. This time for a long-standing bug in the
1951 ;;; compiler's expansion for TYPEP on various class-like things, with
1952 ;;; user-visible consequences.
1953 (defclass obsolete-again
() ())
1954 (defvar *obsolete-again
* (make-instance 'obsolete-again
))
1955 (defvar *obsolete-again-hash
* (sxhash *obsolete-again
*))
1956 (make-instances-obsolete (find-class 'obsolete-again
))
1957 (assert (not (streamp *obsolete-again
*)))
1958 (make-instances-obsolete (find-class 'obsolete-again
))
1959 (assert (= (sxhash *obsolete-again
*) *obsolete-again-hash
*))
1960 (compile (defun is-a-structure-object-p (x) (typep x
'structure-object
)))
1961 (make-instances-obsolete (find-class 'obsolete-again
))
1962 (assert (not (is-a-structure-object-p *obsolete-again
*)))
1964 ;;; overeager optimization of slot-valuish things
1965 (defclass listoid
()
1966 ((caroid :initarg
:caroid
)
1967 (cdroid :initarg
:cdroid
:initform nil
)))
1968 (defmethod lengthoid ((x listoid
))
1970 (loop until
(null x
)
1971 do
(incf result
) (setq x
(slot-value x
'cdroid
)))
1973 (with-test (:name
((:setq
:method-parameter
) slot-value
))
1974 (assert (= (lengthoid (make-instance 'listoid
)) 1))
1975 (assert (= (lengthoid
1976 (make-instance 'listoid
:cdroid
1977 (make-instance 'listoid
:cdroid
1978 (make-instance 'listoid
))))
1983 ;;;; Tests for argument parsing in fast-method-functions.
1987 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
1988 (setf (symbol-value 'a
) 'invalid
))
1990 (defmacro test1
(lambda-list values args
&key declarations cnm
)
1992 (fmakunbound 'll-method
)
1993 (fmakunbound 'll-function
)
1994 (defmethod ll-method ,lambda-list
1997 `((when nil
(call-next-method))))
1999 (defun ll-function ,lambda-list
2003 (assert (equal (ll-method ,@args
)
2004 (ll-function ,@args
))))))
2006 (defmacro test
(&rest args
)
2008 (test1 ,@args
:cnm nil
)
2009 (test1 ,@args
:cnm t
)))
2011 ;; Just plain arguments
2014 (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))
2016 (test (*foo
*) (*foo
* (symbol-value '*foo
*)) (1))
2018 (test (a) (a (symbol-value 'a
)) (1)
2019 :declarations
((declare (special a
))))
2023 (test (a &optional b c
) (a b c
) (1))
2024 (test (a &optional b c
) (a b c
) (1 2))
2025 (test (a &optional b c
) (a b c
) (1 2 3))
2027 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1))
2028 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1 2))
2029 (test (a &optional
(b 'b b-p
) (c 'c c-p
)) (a b c b-p c-p
) (1 2 3))
2031 (test (&optional
*foo
*) (*foo
* (symbol-value '*foo
*)) ())
2032 (test (&optional
*foo
*) (*foo
* (symbol-value '*foo
*)) (1))
2034 (test (&optional
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
) ())
2035 (test (&optional
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
) (1))
2037 (test (&optional a
) (a (symbol-value 'a
)) ()
2038 :declarations
((declare (special a
))))
2039 (test (&optional a
) (a (symbol-value 'a
)) (1)
2040 :declarations
((declare (special a
))))
2042 (test (&optional
(a 'z a-p
)) (a (symbol-value 'a
) a-p
) ()
2043 :declarations
((declare (special a
))))
2044 (test (&optional
(a 'z a-p
)) (a (symbol-value 'a
) a-p
) (1)
2045 :declarations
((declare (special a
))))
2047 (defparameter *count
* 0)
2049 (test (&optional
(a (incf *count
*)) (b (incf *count
*)))
2050 (a b
*count
* (setf *count
* 0))
2053 ;; Keywords with some &RESTs thrown in
2060 (1 :c
3 :c
1 :b
2 :b
4)))
2061 (eval `(test (a &key b c
) (a b c
) ,args
))
2062 (eval `(test (a &key
(b 'b b-p
) (c 'c c-p
))
2065 (eval `(test (a &rest rest
&key
(b 'b b-p
) (c 'c c-p
))
2066 (a b c b-p c-p rest
)
2068 (eval `(test (a &rest
*foo
* &key
(b 'b b-p
) (c 'c c-p
))
2069 (a b c b-p c-p
*foo
* (symbol-value '*foo
*))
2071 (eval `(test (a &rest
*foo
* &key
(b 'b b-p
) (c 'c c-p
))
2072 (a b c b-p c-p
*foo
* (symbol-value '*foo
*))
2074 :declarations
((declare (special b-p
))))))
2078 (:*foo
* 1 :*foo
* 2)))
2079 (eval `(test (&key
*foo
*) (*foo
* (symbol-value '*foo
*)) ,args
))
2080 (eval `(test (&key
(*foo
* 'z foo-p
)) (*foo
* (symbol-value '*foo
*) foo-p
)
2082 (eval `(test (&key
((:*foo
* a
) 'z foo-p
)) (a (symbol-value 'a
) foo-p
)
2084 (eval `(test (&key
((:*foo
* a
) 'z foo-p
)) (a (symbol-value 'a
) foo-p
)
2086 :declarations
((declare (special a
))))))
2088 (defparameter *count
* 0)
2090 (test (&key
(a (incf *count
*)) (b (incf *count
*)))
2091 (a b
*count
* (setf *count
* 0))
2094 (test (&key a b
&allow-other-keys
) (a b
) (:a
1 :b
2 :c
3))
2096 (defmethod clim-style-lambda-list-test (a b
&optional c d
&key x y
)
2099 (clim-style-lambda-list-test 1 2)
2103 (test (&aux
(a (incf *count
*)) (b (incf *count
*)))
2104 (a b
*count
* (setf *count
* 0))
2107 ;;;; long-form method combination with &rest in :arguments
2108 ;;;; (this had a bug what with fixed in 1.0.4.something)
2109 (define-method-combination long-form-with-
&rest
()
2111 (:arguments x
&rest others
)
2113 ,@(mapcar (lambda (method)
2114 `(call-method ,method
))
2116 (list ,x
(length ,others
))))
2118 (defgeneric test-long-form-with-
&rest
(x &rest others
)
2119 (:method-combination long-form-with-
&rest
))
2121 (defmethod test-long-form-with-&rest
(x &rest others
)
2125 (with-test (:name
(define-method-combination :long-form-with-
&rest
))
2126 (assert (equal '(:foo
13)
2127 (apply #'test-long-form-with-
&rest
:foo
(make-list 13)))))
2129 ;;;; slot-missing for non-standard classes on SLOT-VALUE
2131 ;;;; FIXME: This is arguably not right, actually: CLHS seems to say
2132 ;;;; we should just signal an error at least for built-in classes, but
2133 ;;;; for a while we were hitting NO-APPLICABLE-METHOD, which is definitely
2134 ;;;; wrong -- so test this for now at least.
2136 (defvar *magic-symbol
* (gensym "MAGIC"))
2138 (set *magic-symbol
* 42)
2140 (defmethod slot-missing (class instance
(slot-name (eql *magic-symbol
*)) op
2143 (setf (symbol-value *magic-symbol
*) new
)
2144 (symbol-value *magic-symbol
*)))
2146 (with-test (:name
(slot-missing :non-standard-classes
))
2147 (assert (eql 42 (slot-value (cons t t
) *magic-symbol
*)))
2148 (assert (eql 13 (setf (slot-value 123 *magic-symbol
*) 13)))
2149 (assert (eql 13 (slot-value 'foobar
*magic-symbol
*))))
2151 ;;;; Built-in structure and condition layouts should have NIL in
2152 ;;;; LAYOUT-FOR-PCL-OBJ-P, and classes should have T.
2154 (with-test (:name
(sb-pcl::layout-for-pcl-obj-p
:builtin
))
2155 (assert (not (sb-pcl::layout-for-pcl-obj-p
(sb-pcl::find-layout
'warning
))))
2156 (assert (not (sb-pcl::layout-for-pcl-obj-p
(sb-pcl::find-layout
'hash-table
))))
2157 (assert (eq t
(sb-pcl::layout-for-pcl-obj-p
(sb-pcl::find-layout
'standard-object
)))))
2159 ;;;; bug 402: PCL used to warn about non-standard declarations
2160 (declaim (declaration bug-402-d
))
2161 (defgeneric bug-402-gf
(x))
2162 (with-test (:name
(defmethod :non-standard-declaration
:bug-402
))
2163 (handler-bind ((warning #'error
))
2164 (eval '(defmethod bug-402-gf (x)
2165 (declare (bug-402-d x
))
2168 ;;;; non-keyword :default-initargs + :before method on shared initialize
2169 ;;;; interacted badly with CTOR optimizations
2170 (defclass ctor-default-initarg-problem
()
2171 ((slot :initarg slotto
))
2172 (:default-initargs slotto
123))
2173 (defmethod shared-initialize :before
((instance ctor-default-initarg-problem
) slot-names
&rest initargs
)
2174 (format nil
"~&Rock on: ~A~%" initargs
))
2175 (defun provoke-ctor-default-initarg-problem ()
2176 (make-instance 'ctor-default-initarg-problem
))
2177 (with-test (:name
(make-instance :non-keyword-default-initargs
2178 shared-initialize
:before
))
2179 (handler-bind ((warning #'error
))
2180 (assert (= 123 (slot-value (provoke-ctor-default-initarg-problem) 'slot
)))))
2182 ;;;; discriminating net on streams used to generate code deletion notes on
2184 (defgeneric stream-fd
(stream direction
))
2185 (defmethod stream-fd ((stream sb-sys
:fd-stream
) direction
)
2186 (declare (ignore direction
))
2187 (sb-sys:fd-stream-fd stream
))
2188 (defmethod stream-fd ((stream synonym-stream
) direction
)
2189 (stream-fd (symbol-value (synonym-stream-symbol stream
)) direction
))
2190 (defmethod stream-fd ((stream two-way-stream
) direction
)
2194 (two-way-stream-input-stream stream
) direction
))
2197 (two-way-stream-output-stream stream
) direction
))))
2198 (with-test (:name
(:discriminating-name
:code-deletion-note
))
2199 (handler-bind ((compiler-note #'error
))
2200 (stream-fd sb-sys
:*stdin
* :output
)
2201 (stream-fd sb-sys
:*stdin
* :output
)))
2203 (with-test (:name
:bug-380
)
2204 (defclass bug-380
()
2205 ((slot :accessor bug380-slot
)))
2206 (fmakunbound 'foo-slot
)
2207 (defgeneric foo-slot
(x y z
))
2209 ((slot :accessor foo-slot-value
))))
2211 ;;; SET and (SETF SYMBOL-VALUE) used to confuse permuation vector
2214 ((x :initform
:fih
)))
2216 ((x :initform
:fah
)))
2217 (declaim (special *fih
*))
2218 (defmethod fihfah ((*fih
* fih
))
2219 (set '*fih
* (make-instance 'fah
))
2220 (list (slot-value *fih
* 'x
)
2221 (eval '(slot-value *fih
* 'x
))))
2222 (defmethod fihfah ((fah fah
))
2223 (declare (special fah
))
2224 (set 'fah
(make-instance 'fih
))
2225 (list (slot-value fah
'x
)
2226 (eval '(slot-value fah
'x
))))
2227 (with-test (:name
:set-of-a-method-specializer
)
2228 (assert (equal '(:fah
:fah
) (fihfah (make-instance 'fih
))))
2229 (assert (equal '(:fih
:fih
) (fihfah (make-instance 'fah
)))))
2231 (defmethod no-implicit-declarations-for-local-specials ((faax double-float
))
2232 (declare (special faax
))
2233 (set 'faax
(when (< faax
0) (- faax
)))
2235 (with-test (:name
:no-implicit-declarations-for-local-specials
)
2236 (assert (not (no-implicit-declarations-for-local-specials 1.0d0
))))
2238 (defstruct bug-357-a
2241 (slot3 (coerce pi
'single-float
) :type single-float
))
2242 (defclass bug-357-b
(bug-357-a)
2243 ((slot2 :initform
't2
)
2244 (slot4 :initform -
44)
2247 (slot7 :initform
(floor (* pi pi
)))
2248 (slot8 :initform
88))
2249 (:metaclass structure-class
))
2250 (defstruct (bug-357-c (:include bug-357-b
(slot8 -
88) (slot5 :ok
)))
2253 (slot11 (floor (exp 3))))
2254 (with-test (:name
:bug-357
)
2256 (list (bug-357-c-slot1 x
)
2265 (bug-357-c-slot10 x
)
2266 (bug-357-c-slot11 x
))))
2267 (let ((base (slots (make-bug-357-c))))
2268 (assert (equal base
(slots (make-instance 'bug-357-c
))))
2269 (assert (equal base
'(nil t2
3.1415927 -
44 :ok t
9 -
88 nil t
20))))))
2271 (defclass class-slot-shared-initialize
()
2272 ((a :allocation
:class
:initform
:ok
)))
2273 (with-test (:name
:class-slot-shared-initialize
)
2274 (let ((x (make-instance 'class-slot-shared-initialize
)))
2275 (assert (eq :ok
(slot-value x
'a
)))
2276 (slot-makunbound x
'a
)
2277 (assert (not (slot-boundp x
'a
)))
2278 (shared-initialize x
'(a))
2279 (assert (slot-boundp x
'a
))
2280 (assert (eq :ok
(slot-value x
'a
)))))
2282 (declaim (ftype (function (t t t
) (values single-float
&optional
))
2283 i-dont-want-to-be-clobbered-1
2284 i-dont-want-to-be-clobbered-2
))
2285 (handler-bind ((warning #'muffle-warning
))
2286 (defgeneric i-dont-want-to-be-clobbered-1
(x y z
))
2287 (defmethod i-dont-want-to-be-clobbered-2 ((x cons
) y z
)
2289 (defun i-cause-an-gf-info-update ()
2290 (i-dont-want-to-be-clobbered-2 t t t
))
2291 (with-test (:name
(defgeneric :should-clobber-ftype
))
2292 ;; (because it doesn't check the argument or result types)
2293 (assert (equal '(function (t t t
) *)
2294 (sb-kernel:type-specifier
2295 (sb-int:info
:function
2296 :type
'i-dont-want-to-be-clobbered-1
))))
2297 (assert (equal '(function (t t t
) *)
2298 (sb-kernel:type-specifier
2299 (sb-int:info
:function
2300 :type
'i-dont-want-to-be-clobbered-2
))))
2301 (assert (eq :defined-method
2302 (sb-int:info
:function
2303 :where-from
'i-dont-want-to-be-clobbered-1
)))
2304 (assert (eq :defined-method
2305 (sb-int:info
:function
2306 :where-from
'i-dont-want-to-be-clobbered-2
))))
2308 (with-test (:name
:bogus-parameter-specializer-name-error
)
2311 (let ((*error-output
* (make-broadcast-stream)))
2312 (eval `(defmethod #:fii
((x "a string")) 'string
)))
2313 (sb-int:reference-condition
(c)
2314 (when (member '(:ansi-cl
:macro defmethod
)
2315 (sb-int:reference-condition-references c
)
2319 (defclass remove-default-initargs-test
()
2320 ((x :initarg
:x
:initform
42)))
2321 (defclass remove-default-initatgs-test
()
2322 ((x :initarg
:x
:initform
42))
2323 (:default-initargs
:x
0))
2324 (defclass remove-default-initargs-test
()
2325 ((x :initarg
:x
:initform
42)))
2326 (with-test (:name
:remove-default-initargs
)
2327 (assert (= 42 (slot-value (make-instance 'remove-default-initargs-test
)
2330 ;; putting this inside WITH-TEST interferes with recognition of the class name
2332 (defclass bug-485019
()
2333 ((array :initarg
:array
)))
2334 (with-test (:name
:bug-485019
)
2335 ;; there was a bug in WALK-SETQ, used in method body walking, in the
2336 ;; presence of declarations on symbol macros.
2337 (defmethod bug-485019 ((bug-485019 bug-485019
))
2338 (with-slots (array) bug-485019
2339 (declare (type (or null simple-array
) array
))
2340 (setf array
(make-array 4)))
2342 (funcall 'bug-485019
(make-instance 'bug-485019
)))
2344 ;;; The compiler didn't propagate the declarared type before applying
2345 ;;; the transform for (SETF SLOT-VALUE), so the generic accessor was used.
2346 (defstruct foo-520366
2348 (defun quux-520366 (cont)
2350 (defun bar-520366 (foo-struct)
2351 (declare (type foo-520366 foo-struct
))
2352 (with-slots (slot) foo-struct
2354 (quux-520366 #'(lambda ()
2358 (with-test (:name
:bug-520366
)
2359 (let ((callees (find-named-callees #'bar-520366
)))
2360 (assert (equal (list #'quux-520366
) callees
))))
2362 (defgeneric no-applicable-method
/retry
(x))
2363 (defmethod no-applicable-method/retry
((x string
))
2365 (with-test (:name
:no-applicable-method
/retry
)
2366 (assert (equal "cons"
2367 (handler-bind ((sb-pcl::no-applicable-method-error
2369 (declare (ignore c
))
2370 (let ((r (find-restart 'sb-pcl
::retry
)))
2372 (eval `(defmethod no-applicable-method/retry
((x cons
))
2374 (invoke-restart r
))))))
2375 (no-applicable-method/retry
(cons t t
))))))
2377 (defgeneric no-primary-method
/retry
(x))
2378 (defmethod no-primary-method/retry
:before
(x) (assert x
))
2379 (with-test (:name
:no-primary-method
/retry
)
2380 (assert (equal "ok!"
2381 (handler-bind ((sb-pcl::no-primary-method-error
2383 (declare (ignore c
))
2384 (let ((r (find-restart 'sb-pcl
::retry
)))
2386 (eval `(defmethod no-primary-method/retry
(x)
2388 (invoke-restart r
))))))
2389 (no-primary-method/retry
(cons t t
))))))
2391 ;;; test that a cacheing strategy for make-instance initargs checking
2392 ;;; can handle class redefinitions
2394 (defun cacheing-initargs-redefinitions-make-instances
2395 (&optional
(initarg :slot
))
2396 (declare (notinline make-instance
))
2397 (make-instance 'cacheing-initargs-redefinitions-check
)
2398 (make-instance 'cacheing-initargs-redefinitions-check initarg
3))
2400 (defclass cacheing-initargs-redefinitions-check
()
2401 ((slot :initarg
:slot
)))
2403 (with-test (:name
(make-instance :initargs-checking-before-redefinition
))
2404 (make-instance 'cacheing-initargs-redefinitions-check
)
2405 (make-instance 'cacheing-initargs-redefinitions-check
:slot
3)
2406 (cacheing-initargs-redefinitions-make-instances :slot
)
2407 (assert-error (cacheing-initargs-redefinitions-make-instances :slot2
)))
2409 (defclass cacheing-initargs-redefinitions-check
()
2410 ((slot :initarg
:slot2
)))
2412 (with-test (:name
(make-instance :initargs-checking-after-redefinition
))
2413 (make-instance 'cacheing-initargs-redefinitions-check
)
2414 (make-instance 'cacheing-initargs-redefinitions-check
:slot2
3)
2415 (cacheing-initargs-redefinitions-make-instances :slot2
)
2416 (assert-error (cacheing-initargs-redefinitions-make-instances :slot
)))
2418 (defmethod initialize-instance :after
2419 ((class cacheing-initargs-redefinitions-check
) &key slot
)
2420 (declare (ignore slot
))
2423 (with-test (:name
(make-instance :initargs-checking-new-method-initargs
))
2424 (make-instance 'cacheing-initargs-redefinitions-check
)
2425 (make-instance 'cacheing-initargs-redefinitions-check
:slot2
3)
2426 (cacheing-initargs-redefinitions-make-instances :slot2
)
2427 (let ((thing (cacheing-initargs-redefinitions-make-instances :slot
)))
2428 (assert (not (slot-boundp thing
'slot
)))))
2433 (with-test (:name
(defmethod :specializer-builtin-class-alias
:bug-618387
))
2434 (let ((alias (gensym)))
2435 (setf (find-class alias
) (find-class 'symbol
))
2436 (eval `(defmethod lp-618387 ((s ,alias
))
2438 (assert (equal "FOO" (funcall 'lp-618387
:foo
)))))
2440 (with-test (:name
(defmethod :pcl-spurious-ignore-warnings
))
2441 (defgeneric no-spurious-ignore-warnings
(req &key key
))
2442 (handler-bind ((warning (lambda (x) (error "~A" x
))))
2444 '(defmethod no-spurious-ignore-warnings ((req number
) &key key
)
2445 (declare (ignore key
))
2446 (check-type req integer
))))
2447 (defgeneric should-get-an-ignore-warning
(req &key key
))
2449 (handler-bind ((warning (lambda (c) (setq warnings
1) (muffle-warning c
))))
2450 (eval '(defmethod should-get-an-ignore-warning ((req integer
) &key key
)
2451 (check-type req integer
))))
2452 (assert (= warnings
1))))
2454 (handler-bind ((style-warning #'muffle-warning
))
2455 (eval '(defgeneric generic-function-pretty-arglist-optional-and-key
(req &optional opt
&key key
)
2456 (:method
(req &optional opt
&key key
)
2457 (list req opt key
)))))
2458 (with-test (:name
:generic-function-pretty-arglist-optional-and-key
)
2459 (handler-bind ((warning #'error
))
2460 ;; Used to signal a style-warning
2461 (assert (equal '(req &optional opt
&key key
)
2462 (sb-pcl::generic-function-pretty-arglist
2463 #'generic-function-pretty-arglist-optional-and-key
)))))
2465 (with-test (:name
:bug-894202
)
2468 (let ((name (gensym "FOO"))
2469 (decl (gensym "BAR")))
2470 (eval `(defgeneric ,name
()
2471 (declare (,decl
)))))
2475 (with-test (:name
:bug-898331
)
2476 (handler-bind ((warning #'error
))
2477 (eval `(defgeneric bug-898331
(request type remaining-segment-requests all-requests
)))
2478 (eval `(defmethod bug-898331 ((request cons
) (type (eql :cancel
))
2479 remaining-segment-requests
2480 all-segment-requests
)
2481 (declare (ignore all-segment-requests
))
2482 (check-type request t
)))))
2484 (with-test (:name
(defmethod :bug-1001799
))
2485 ;; compilation of the defmethod used to cause infinite recursion
2486 (let ((pax (gensym "PAX"))
2487 (pnr (gensym "PNR"))
2488 (sup (gensym "SUP"))
2489 (frob (gensym "FROB"))
2490 (sb-ext:*evaluator-mode
* :compile
))
2493 (declaim (optimize (speed 1) (space 1) (safety 3) (debug 3) (compilation-speed 1)))
2494 (defclass ,pax
(,sup
)
2495 ((,pnr
:type
(or null
,pnr
))))
2496 (defclass ,pnr
(,sup
)
2497 ((,pax
:type
(or null
,pax
))))
2500 (defmethod ,frob
((pnr ,pnr
))
2501 (slot-value pnr
',pax
))
2502 (declaim (optimize (safety 1) (debug 1)))))))
2504 (defclass bug-1099708
() ((slot-1099708 :initarg
:slot-1099708
)))
2505 (defun make-1099708-1 ()
2506 (make-instance 'bug-1099708
:slot-1099708
'#1= (1 2 .
#1#)))
2507 (defun make-1099708-2 ()
2508 (make-instance 'bug-1099708
:slot-1099708
'#2= (1 2 .
#2#)))
2509 (with-test (:name
:bug-1099708
)
2510 ;; caused infinite equal testing in function name lookup
2511 (assert (not (eql (slot-value (make-1099708-1) 'slot-1099708
)
2512 (slot-value (make-1099708-2) 'slot-1099708
)))))
2514 (defclass bug-1099708b-list
()
2515 ((slot-1099708b-list :initarg
:slot-1099708b-list
)))
2516 (defun make-1099708b-list-1 ()
2517 (make-instance 'bug-1099708b-list
:slot-1099708b-list
'(some value
)))
2518 (defun make-1099708b-list-2 ()
2519 (make-instance 'bug-1099708b-list
:slot-1099708b-list
'(some value
)))
2520 (with-test (:name
:bug-1099708b-list
)
2521 (assert (eql (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)
2522 (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)))
2523 (assert (eql (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)
2524 (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)))
2525 (assert (not (eql (slot-value (make-1099708b-list-1) 'slot-1099708b-list
)
2526 (slot-value (make-1099708b-list-2) 'slot-1099708b-list
)))))
2528 (defclass bug-1099708b-string
()
2529 ((slot-1099708b-string :initarg
:slot-1099708b-string
)))
2530 (defun make-1099708b-string-1 ()
2531 (make-instance 'bug-1099708b-string
:slot-1099708b-string
"string"))
2532 (defun make-1099708b-string-2 ()
2533 (make-instance 'bug-1099708b-string
:slot-1099708b-string
"string"))
2534 (with-test (:name
:bug-1099708b-string
)
2535 (assert (eql (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)
2536 (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)))
2537 (assert (eql (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)
2538 (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)))
2539 (assert (not (eql (slot-value (make-1099708b-string-1) 'slot-1099708b-string
)
2540 (slot-value (make-1099708b-string-2) 'slot-1099708b-string
)))))
2542 (defclass bug-1099708b-bitvector
()
2543 ((slot-1099708b-bitvector :initarg
:slot-1099708b-bitvector
)))
2544 (defun make-1099708b-bitvector-1 ()
2545 (make-instance 'bug-1099708b-bitvector
:slot-1099708b-bitvector
#*1011))
2546 (defun make-1099708b-bitvector-2 ()
2547 (make-instance 'bug-1099708b-bitvector
:slot-1099708b-bitvector
#*1011))
2548 (with-test (:name
:bug-1099708b-bitvector
)
2549 (assert (eql (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)
2550 (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)))
2551 (assert (eql (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)
2552 (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)))
2553 (assert (not (eql (slot-value (make-1099708b-bitvector-1) 'slot-1099708b-bitvector
)
2554 (slot-value (make-1099708b-bitvector-2) 'slot-1099708b-bitvector
)))))
2556 (defclass bug-1099708b-pathname
()
2557 ((slot-1099708b-pathname :initarg
:slot-1099708b-pathname
)))
2558 #+nil
; after change 58602640ed, I don't see how to make this assert something useful
2559 (with-test (:name
:bug-1099708b-pathname
)
2560 (defun make-1099708b-pathname-1 ()
2561 (make-instance 'bug-1099708b-pathname
:slot-1099708b-pathname
#p
"pn"))
2562 (defun make-1099708b-pathname-2 ()
2563 (make-instance 'bug-1099708b-pathname
:slot-1099708b-pathname
#p
"pn"))
2564 (assert (eql (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)
2565 (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)))
2566 (assert (eql (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)
2567 (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)))
2568 (assert (not (eql (slot-value (make-1099708b-pathname-1) 'slot-1099708b-pathname
)
2569 (slot-value (make-1099708b-pathname-2) 'slot-1099708b-pathname
)))))
2571 (defclass bug-1099708c-list
()
2572 ((slot-1099708c-list :initarg
:slot-1099708c-list
)))
2574 (defun make-1099708c-list-1 ()
2575 (make-instance 'bug-1099708c-list
:slot-1099708c-list
#1='(some value
)))
2576 (defun make-1099708c-list-2 ()
2577 (make-instance 'bug-1099708c-list
:slot-1099708c-list
#1#)))
2578 (with-test (:name
:bug-1099708c-list
)
2579 (assert (eql (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)
2580 (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)))
2581 (assert (eql (slot-value (make-1099708c-list-2) 'slot-1099708c-list
)
2582 (slot-value (make-1099708c-list-2) 'slot-1099708c-list
)))
2583 (assert (eql (slot-value (make-1099708c-list-1) 'slot-1099708c-list
)
2584 (slot-value (make-1099708c-list-2) 'slot-1099708c-list
))))
2588 ;;; Define a class and force the "fallback" constructor generator to be
2589 ;;; used by having a HAIRY-AROUND-OR-NONSTANDARD-PRIMARY-METHOD-P on
2590 ;;; SHARED-INITIALIZE.
2591 (defclass bug-1179858
()
2592 ((foo :initarg
:foo
:reader bug-1179858-foo
))
2593 (:default-initargs
:foo
(error "Should not be evaluated")))
2594 (defmethod shared-initialize :around
((instance bug-1179858
) (slot-names t
) &key
)
2597 (with-test (:name
(make-instance :fallback-generator-initarg-handling
:bug-1179858
))
2598 ;; Now compile a lambda containing MAKE-INSTANCE to exercise the
2599 ;; fallback constructor generator. Call the resulting compiled
2600 ;; function to trigger the bug.
2601 (checked-compile-and-assert ()
2602 '(lambda () (make-instance 'bug-1179858
:foo t
))
2603 (() nil
:test
(constantly t
))))
2605 ;;; Other brokenness, found while investigating: fallback-generator
2606 ;;; handling of non-keyword initialization arguments
2607 (defclass bug-1179858b
()
2608 ((foo :initarg foo
:reader bug-1179858b-foo
))
2609 (:default-initargs foo
14))
2610 (defmethod shared-initialize :around
((instance bug-1179858b
) (slot-names t
) &key
)
2613 (with-test (:name
(make-instance :fallback-generator-non-keyword-initarg
:bug-1179858
))
2614 (flet ((foo= (n i
) (= (bug-1179858b-foo i
) n
)))
2616 (foo= 14 (funcall (checked-compile '(lambda () (make-instance 'bug-1179858b
))))))
2618 (foo= 15 (funcall (checked-compile '(lambda () (make-instance 'bug-1179858b
'foo
15))))))))
2620 (with-test (:name
(:cpl-violation-setup
:bug-309076
))
2623 (defclass bug-309076-broken-class
(standard-class) ()
2624 (:metaclass sb-mop
:funcallable-standard-class
))
2625 (sb-mop:finalize-inheritance
(find-class 'bug-309076-broken-class
)))))
2627 (defclass bug-309076-class
(standard-class) ())
2628 (with-test (:name
(:cpl-violation-irrelevant-class
:bug-309076
))
2629 (defmethod sb-mop:validate-superclass
((x bug-309076-class
) (y standard-class
)) t
)
2630 (assert (typep (make-instance 'bug-309076-class
) 'bug-309076-class
)))
2632 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
2638 (declare (special a
))
2639 (checked-compile-and-assert ()
2640 (sb-mop:make-method-lambda
2642 (find-method #'b
() ())
2643 '(lambda () (declare (special a
)) a
)
2647 (with-test (:name
:make-method-lambda-leakage
)
2648 ;; lambda list of X leaks into the invocation of make-method-lambda
2649 ;; during code-walking performed by make-method-lambda invoked by
2651 (sb-cltl2:macroexpand-all
'(defmethod x (a) (macro))))
2653 (with-test (:name
(defmethod :undefined-function
:bug-503095
))
2654 (flet ((test-load (file)
2656 (((or warning error
) #'error
))
2658 (multiple-value-bind (fasl warnings errorsp
)
2659 (compile-file "bug-503095.lisp" :print nil
:verbose nil
2660 :output-file
(scratch-file-name "fasl"))
2662 (progn (assert (and fasl
(not warnings
) (not errorsp
)))
2664 (and fasl
(delete-file fasl
))))
2665 (test-load "bug-503095-2.lisp")))
2667 (defclass a-633911
()
2668 ((x-633911 :initform nil
2669 :accessor x-633911
)))
2670 (defclass b-633911
()
2671 ((x-633911 :initform nil
2672 :accessor x-633911
)))
2673 (with-test (:name
:accessor-and-plain-method
)
2674 (defmethod x-633911 ((b a-633911
)) 10)
2675 (assert (= (x-633911 (make-instance 'a-633911
)) 10)))
2677 (with-test (:name
(built-in-class :subclass error
))
2679 (when (and (class-name c
) (typep c
'built-in-class
))
2680 (assert-error (eval `(defclass ,(gensym) (,(class-name c
))
2682 (sb-pcl::map-all-classes
#'mapper
)))
2684 (defclass slot-value-using-class-a
() ())
2685 (defclass slot-value-using-class-b
() (x))
2687 (with-test (:name
:svuc-with-bad-slotd
)
2688 (let* ((a (make-instance 'slot-value-using-class-a
))
2689 (b (make-instance 'slot-value-using-class-b
))
2690 (slotd (car (sb-mop:class-slots
(class-of b
)))))
2691 (assert-error (sb-mop:slot-value-using-class
(class-of a
) a slotd
))
2692 (assert-error (setf (sb-mop:slot-value-using-class
(class-of a
) a slotd
) t
))))
2694 ;; A test that the *FGENS* cache works.
2695 ;; This is not a test in the CLOS problem domain, but in the implementation
2696 ;; of discriminating functions.
2697 (defgeneric f
(x y
) (:method
(x y
) (+ x y
)))
2698 (defgeneric g
(x y
) (:method
(x y
) (* x y
)))
2699 (with-test (:name
:fgens-sharing
)
2700 (let ((count0 (hash-table-count sb-pcl
::*fgens
*))
2702 (count1 (hash-table-count sb-pcl
::*fgens
*))
2704 (count2 (hash-table-count sb-pcl
::*fgens
*)))
2705 (declare (ignore foo bar
))
2706 (assert (= count0 count1 count2
))))
2709 ;;; Classes shouldn't be their own direct or indirect superclasses or
2712 (with-test (:name
(sb-mop:ensure-class
:class-is-direct-superclass
2715 (defclass class-with-self-as-superclass
(class-with-self-as-superclass) ())))
2717 (with-test (:name
(sb-mop:ensure-class
:superclass-cycle
:bug-1418883
))
2718 ;; These have a superclass cycle from the beginning.
2719 (defclass class-with-superclass-cycle1
(class-with-superclass-cycle2) ())
2721 (defclass class-with-superclass-cycle2
(class-with-superclass-cycle1) ())))
2723 (with-test (:name
(sb-mop:ensure-class
:self-metaclass
))
2724 ;; These have a metaclass cycle from the beginning.
2726 (defclass class-with-self-as-metaclass
() ()
2727 (:metaclass class-with-self-as-metaclass
))))
2729 (with-test (:name
(sb-pcl::update-class
:class-becomes-direct-superclass
2731 (defclass class-with-eventual-self-as-superclass
() ())
2732 ;; Update class to introduce superclass.
2734 (defclass class-with-eventual-self-as-superclass
2735 (class-with-eventual-self-as-superclass) ())))
2737 (with-test (:name
(sb-pcl::update-class
:superclasses-become-cyclic
2739 ;; Nothing wrong with these.
2740 (defclass class-with-eventual-superclass-cycle1
() ())
2741 (defclass class-with-eventual-superclass-cycle2
2742 (class-with-eventual-superclass-cycle1) ())
2743 ;; Update first class to introduce the superclass cycle.
2745 (defclass class-with-eventual-superclass-cycle1
2746 (class-with-eventual-superclass-cycle2) ())))
2748 (with-test (:name
(sb-pcl::update-class
:becomes-self-metaclass
))
2749 (defclass class-with-eventual-self-as-metaclass
() ())
2750 ;; Try to update metaclass to self.
2752 (defclass class-with-eventual-self-as-metaclass
() ()
2753 (:metaclass class-with-eventual-self-as-metaclass
))))
2755 (with-test (:name
:function-keywords
)
2756 (defgeneric function-keywords-test
(&key
))
2757 (assert (equal (function-keywords
2758 (defmethod function-keywords-test (&key a b
)
2759 (declare (ignore a b
))))
2762 (with-test (:name
:superclass-finalization
)
2763 (let* ((class1 (gensym "CLASS1-"))
2764 (class2 (gensym "CLASS2-")))
2765 (eval `(defclass ,class1
() ()))
2766 (eval `(defclass ,class2
(,class1
) ()))
2767 (let ((instance (make-instance class2
)))
2768 (sb-mop:finalize-inheritance
(find-class class1
))
2769 (assert (not (sb-kernel:layout-invalid
(sb-kernel:layout-of instance
)))))))
2771 (with-test (:name
(allocate-instance :on symbol
))
2772 (let ((class (gensym "CLASS-")))
2773 (eval `(defclass ,class
() ()))
2774 (checked-compile-and-assert ()
2775 `(lambda () (allocate-instance ',class
))
2776 (() (condition 'sb-pcl
::no-applicable-method-error
)))))
2778 (defclass unbound-slot-after-allocation
=class
()
2779 ((abc :allocation
:class
)
2780 (d :accessor unbound-slot-after-allocation
=class
)))
2782 (with-test (:name
:unbound-slot-after-allocation
=class
)
2783 (assert-error (unbound-slot-after-allocation=class
2784 (make-instance 'unbound-slot-after-allocation
=class
))
2787 (with-test (:name
:layouf-of-nil
)
2788 (assert (eq (sb-kernel:layout-of nil
) (sb-kernel:find-layout
'null
))))
2790 (with-test (:name
(defmethod :on-classless-type
))
2791 (handler-bind ((timeout (lambda (condition)
2792 (declare (ignore condition
))
2793 (error "Timeout"))))
2794 (sb-ext:with-timeout
10
2795 (checked-compile-and-assert (:allow-warnings t
)
2797 (defmethod foo ((bar keyword
))))
2798 (() (condition 'sb-pcl
:class-not-found-error
))))))
2800 (defclass removing-a-class
() ())
2802 (defvar *removing-a-class
* (sb-ext:make-weak-pointer
(find-class 'removing-a-class
)))
2803 (setf (find-class 'removing-a-class
) nil
)
2804 (sb-mop:remove-direct-subclass
(find-class 'standard-object
)
2805 (sb-ext:weak-pointer-value
*removing-a-class
*))
2807 (with-test (:name
:removing-a-class
:fails-on
:permgen
)
2809 (assert (not (sb-ext:weak-pointer-value
*removing-a-class
*))))
2811 (locally (declare (optimize safety
))
2812 (defclass setf-slot-value-restart
()
2814 :accessor setf-slot-value-restart-a
))))
2816 (with-test (:name
:setf-slot-value-restart
2817 :skipped-on
:sparc
) ; hangs
2818 (let ((instance (make-instance 'setf-slot-value-restart
)))
2819 (handler-bind ((type-error
2820 (lambda (c) (use-value 1 c
))))
2821 (setf (slot-value instance
'a
) 'x
))
2822 (assert (eql (slot-value instance
'a
) 1))
2823 (handler-bind ((type-error
2824 (lambda (c) (use-value 2 c
))))
2825 (setf (setf-slot-value-restart-a instance
) 'y
))
2826 (assert (eql (setf-slot-value-restart-a instance
) 2))))