ccl
ccl copied to clipboard
Maybe spurious warning about shadowed single-float/short-float in typecase
Maxima has this function:
(defun extreme-float-values (x)
(typecase x
(short-float (values most-negative-short-float most-positive-short-float))
(single-float (values most-negative-single-float most-positive-single-float))
(double-float (values most-negative-double-float most-positive-double-float))
(long-float (values most-negative-long-float most-positive-long-float))))
CCL64 (1.12.2 (v1.12.2-66-g7e9ea2a9) LinuxX8664) prints this warning when compiling this form:
;Compiler warnings for "home:src;sourceforge;maxima;src;float.lisp.newest" :
; Clause (SINGLE-FLOAT (VALUES MOST-NEGATIVE-SINGLE-FLOAT MOST-POSITIVE-SINGLE-FLOAT)) ignored in TYPECASE form - shadowed by (SHORT-FLOAT (VALUES MOST-NEGATIVE-SHORT-FLOAT MOST-POSITIVE-SHORT-FLOAT)) .
; Clause (LONG-FLOAT (VALUES MOST-NEGATIVE-LONG-FLOAT MOST-POSITIVE-LONG-FLOAT)) ignored in TYPECASE form - shadowed by (DOUBLE-FLOAT (VALUES MOST-NEGATIVE-DOUBLE-FLOAT MOST-POSITIVE-DOUBLE-FLOAT)) .
I can see it can be useful especially if the clauses for single-float and short-float have truly different results. In this case, the results aren't actually different since most-negative-single-float and most-negative-short-float are eq.
Other lisps (clisp, cmucl) don't warn about this.
I suppose a way to suppress this warning would be acceptable. (Need to read the manual to see if this is possible.)
The warning is a ccl::shadowed-typecase-clause, which is a subtype of style-warning.
https://trac.clozure.com/ccl/ticket/872
So, you could write something like the following to suppress it.
(handler-bind ((warning
(lambda (c)
(if (typep c 'ccl::shadowed-typecase-clause)
(muffle-warning c)))))
(load "~/f.lisp"))
Maybe cl:style-warning instead of ccl::shadowed-typecase-clause would be preferable, to avoid the internal symbol (I don't know why it's internal, to be honest).
Thanks for your suggestion. I'll look into how to use this to silence the warning.
Feel free to close this issue, if this is the intended behavior.
I'm going to close this as "working as intended".
The entry in the spec for typecase says
The compiler may choose to issue a warning of type style-warning if a clause will never be selected because it is completely shadowed by earlier clauses.
I hope that it is not too burdensome to muffle style-warnings in cases like this where the shadowing is known to be harmless.