Using MULTIPLE-VALUE-CALL as a conditional in IF can lead to unnecessary STYLE-WARNINGs due to type propagation
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
What I do:
(let ((cachep :empty))
(+
(if (multiple-
cachep)
0)
10))
What happens:
SBCL reports a STYLE-WARNING:
"This is not a NUMBER: NOT-A-NUMBER"
What I expected to happen:
Since the branch that would eventually result in an error is never actually taken, I shouldn't get a warning.
Note that replacing the MULTIPLE-VALUE-CALL with FUNCALL solves the problem, which hints that this really is a bug and that MULTIPLE-VALUE-CALL is the culprit.
SBCL version: 1.0.42
uname -a: Linux dynamorph 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
*features*:
(:SWANK :QUICKLISP :SB-BSD-
:SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
:SB-SOURCE-
:LARGEFILE :GENCGC :STACK-
:COMPARE-
:STACK-
:STACK-
:CYCLE-COUNTER :INLINE-CONSTANTS :MEMORY-
:OS-PROVIDES-
Not a MULTIPLE-VALUE-CALL issue, really -- just plain old type inference.
CL-USER> (compile nil `(lambda (x) (+ 1 (if x 1 :not-a-number))))
; in: LAMBDA (X)
; (+ 1
; (IF X
; 1
; :NOT-A-NUMBER))
;
; note: deleting unreachable code
;
; caught WARNING:
; Asserted type NUMBER conflicts with derived type
; (VALUES (MEMBER :NOT-A-NUMBER) &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
; printed 1 note
#<FUNCTION (LAMBDA (X)) {1002C8F649}>
T
T
In your example the difference between MULTIPLE-VALUE-CALL and FUNCALL is due to SBCL's current inability to use type inference with MULTIPLE-VALUE-CALL -- so the IF is not eliminated as it cannot prove that the NOT-A-NUMBER case never happens.
For clarity's sake I'm marking this a duplicate of