As was recently mentioned both on usenet and on IRC, SBCL doesn't
use the implications of check-type in its type derivation.
This expansion of (check-type n fixnum) might show why:
(DO ((#:G3824 N N))
((TYPEP #:G3824 'FIXNUM))
(SETF N (SB-KERNEL:CHECK-TYPE-ERROR 'N #:G3824 'FIXNUM NIL)))
I'm guessing that this lets python derive the type of the
gensym-named variable, but not of N. Compare to this expansion
(courtesy of the attached patch):
((TYPEP N 'FIXNUM))
(SETF N (SB-KERNEL:CHECK-TYPE-ERROR 'N N 'FIXNUM NIL)))
And indeed, now python does derive the type of n after the
check-type form. The only downside that I can see is that the
place (N, in this case) is evaluated twice in case the type
doesn't match, but I don't see why this would be a problem, and
it even seems to be explicitly allowed by 22.214.171.124, third item.
(I wouldn't be very suprised however, if someone with more
knowledge of the language would tell me I'm wrong here.)
Thank you for the patch. The same problem we have with
TYPECASE/ETYPECASE/CTYPECASE with variables being written.
Vincent Arkesteijn <vincent@...> writes:
> The only downside that I can see is that the
> place (N, in this case) is evaluated twice in case the type
> doesn't match, but I don't see why this would be a problem, and
On the one hand, those who use side-effectful places in CHECK-TYPE
probably deserve to loose, but this error message is somewhat
| * (let ((x (vector 1 2 3 4 5 6)) (i 0))
| (check-type (aref x (incf i)) (integer 3))
| (print i))
| debugger invoked on a SIMPLE-TYPE-ERROR in thread 2671:
| The value of (AREF X (INCF I)) is 4, which is not of type (INTEGER 3).
| restarts (invokable by number or by possibly-abbreviated name):
| 0: [STORE-VALUE] Supply a new value for (AREF X (INCF I)).
| 1: [ABORT ] Reduce debugger level (leaving debugger, returning to
| 2: [TOPLEVEL ] Restart at toplevel READ/EVAL/PRINT loop.
| (CHECK-TYPE-ERROR 4 (AREF X (INCF I)) 4 (INTEGER 3) NIL)[:EXTERNAL]
| 0] (typep 4 '(integer 3))
"Alas, the spheres of truth are less transparent than those of
illusion." -- L.E.J. Brouwer