I apparently encountered this same problem in (https://bugs.launchpad.net/sbcl/+bug/1558695).
My case was the following:
(in-package :cl-user)
(defclass B () ())
;; test-function-subtype takes an argument which is a ;; unary function B->B (defun test-function-subtype (f) (declare (type (function (B) B) f) (optimize (debug 3) (speed 0) (safety 3))) (let ((ret-val (funcall f (make-instance 'B)))) (format t "ret-val = ~A (typep ret-val 'B)=~A~%" ret-val (typep ret-val 'B)) (assert (typep ret-val 'B))))
;; But I cannot make the return less specific (test-function-subtype #'(lambda (b) (declare (type B b)) 12))
----------------------------
The compiler apparently replaces (typep ret-val 'B) with t. And at run-time the value of ret-val is 12, which is NOT of type B.
I apparently encountered this same problem in (https:/ /bugs.launchpad .net/sbcl/ +bug/1558695).
My case was the following:
(in-package :cl-user)
(defclass B ()
())
;; test-function- subtype takes an argument which is a subtype (f)
;; unary function B->B
(defun test-function-
(declare (type (function (B) B) f)
(optimize (debug 3) (speed 0) (safety 3)))
(let ((ret-val (funcall f (make-instance 'B))))
(format t "ret-val = ~A (typep ret-val 'B)=~A~%" ret-val (typep ret-val 'B))
(assert (typep ret-val 'B))))
;; But I cannot make the return less specific subtype #'(lambda (b)
(test-function-
(declare (type B b))
12))
------- ------- ------- -------
The compiler apparently replaces (typep ret-val 'B) with t. And at run-time
the value of ret-val is 12, which is NOT of type B.