Next: Errors During Macroexpansion, Up: Compiler Errors

#### 4.4.1 Type Errors at Compile Time

If the compiler can prove at compile time that some portion of the program cannot be executed without a type error, then it will give a warning at compile time.

It is possible that the offending code would never actually be executed at run-time due to some higher level consistency constraint unknown to the compiler, so a type warning doesn't always indicate an incorrect program.

For example, consider this code fragment:

         (defun raz (foo)
           (let ((x (case foo
                       (:this 13)
                       (:that 9)
                       (:the-other 42))))
             (declare (fixnum x))
             (foo x)))

Compilation produces this warning:

         ; in: DEFUN RAZ
         ;     (CASE FOO (:THIS 13) (:THAT 9) (:THE-OTHER 42))
         ; --> LET COND IF COND IF COND IF
         ; ==>
         ;   (COND)
         ;
         ; caught WARNING:
         ;   This is not a FIXNUM:
         ;   NIL

In this case, the warning means that if `foo` isn't any of `:this`, `:that` or `:the-other`, then `x` will be initialized to `nil`, which the `fixnum` declaration makes illegal. The warning will go away if `ecase` is used instead of `case`, or if `:the-other` is changed to `t`.

This sort of spurious type warning happens moderately often in the expansion of complex macros and in inline functions. In such cases, there may be dead code that is impossible to correctly execute. The compiler can't always prove this code is dead (could never be executed), so it compiles the erroneous code (which will always signal an error if it is executed) and gives a warning.