title: Can Common Lisp type annotations result in unsound behavior?
body: <p>I know that if the safety setting is low, Common Lisp can use type annotations as optimization aids and are not checked. For example, this program runs and prints both the number and the string without any type errors. (I only get a type error in SBCL, when safety >= 1)</p>
  
  <pre><code>(declaim (optimize
             (speed 3)
             (safety 0)))
  
  (defun f (x)
    (declare (type fixnum x))
    x)
  
  (format t "1 ~A~%" (f 17))
  (format t "2 ~A~%" (f "asd"))
  </code></pre>
  
  <p>I now wonder if its possible to create a program that does nasty things if safety is set to zero and type annotations are not respected. Things like casting from one type to another (like C type casts) and other kinds of undefined behavior.</p>
  
  <p>So far, I haven't managed to find out an example that does that. I tried variations of this example that uses typed arrays but none of them resulted in typecasting behavior.</p>
  
  <pre><code>(declaim (optimize
             (speed 3)
             (safety 0)
             ))
  
  (defun f ()
      (let ((arr (make-array '(5)
        :element-type 'fixnum
        :initial-contents (list 1 2 3 4 5))))
        (declare (type (vector fixnum 5) arr))
        (setf (aref arr 0) "hello")
        (aref arr 0)))
  
  (format t "a1 ~A~%" (f))
  </code></pre>
  
  <p>In CLISP, this program prints "hello", without doing a typecast to int and in SBCL the program aborts with a SIMPLE-TYPE-ERROR error.</p>
  
  <p>Is there a way to create a Common Lisp program that results in demons coming out of my nose if I don't respect my type declarations?</p>