Hi!
This is with 19a-pre3:
* (defun foo (list)
(let ((x (if list
(* 2 (length list)))))
(loop for el in list
sum (+ 3 x))))
FOO
* (compile 'foo)
; Compiling LAMBDA (LIST):
; In: LAMBDA (LIST)
; (IF LIST (* 2 #))
; Warning: This is not a (VALUES &OPTIONAL NUMBER &REST T):
; NIL
; ; [Last message occurs 2 times]
; Compiling Top-Level Form:
; Compilation unit finished.
; 2 warnings
FOO
T
T
I obviously get this warning because the compiler sees the (+ 3 X)
form and deduces that X must be a number but can potentially be NIL
(if LIST is NIL). I have two (miniscule) problems here:
1. The compiler can't deduce that the (+ 3 X) will only be executed if
LIST is not NIL (and thus X not NIL). Even if I change FOO like
this
(defun foo (list)
(let ((x (if list
(* 2 (length list)))))
(locally
(declare (number x))
(loop for el in list
sum (+ 3 x)))))
I get the same message.
2. The warning is not really helpful. In most cases I came across the
forms were more complicated and you had to do a lot of guesswork to
find out why the compiler complained. It would be better (if that's
possible) if it said something like "This is not a ... which will
potentially lead to problems in (+ 3 X)."
Cheers,
Edi.