Some code:
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass test () ()))
(declaim (inline dispatch))
(defun dispatch (arg)
(typecase arg
(test 40)
(t (list 40))))
(defun test ()
(+ 2 (dispatch (make-instance 'test))))
CL-USER> (compile-file "/home/lnostdal/lisp/tmp/typecase-test")
; compiling file "/home/lnostdal/clbuild/source/tmp/typecase-test.lisp" (written 28 OCT 2009 07:26:22 AM):
; compiling (DEFCLASS TEST ...)
; compiling (DECLAIM (INLINE DISPATCH))
; compiling (DEFUN DISPATCH ...)
; compiling (DEFUN TEST ...)
; file: /home/lnostdal/clbuild/source/tmp/typecase-test.lisp
; in: DEFUN TEST
; (+ 2 (DISPATCH (MAKE-INSTANCE 'TEST)))
;
; note: deleting unreachable code
;
; caught WARNING:
; Asserted type NUMBER conflicts with derived type (VALUES CONS &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
; printed 1 note
; /home/lnostdal/lisp/tmp/typecase-test.fasl written
; compilation finished in 0:00:00.114
#P"/home/lnostdal/clbuild/source/tmp/typecase-test.fasl"
T
T
CL-USER> (load "/home/lnostdal/lisp/tmp/typecase-test")
T
CL-USER> (test)
42
CL-USER>
The warning stops compilation (ASDF, I think) and generates a ton of
output in some cases. How does one deal with this? E.g., doing this does
not seem like a good solution:
(defun test ()
(locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note warning))
(+ 2 (dispatch (make-instance 'test)))))
|