Howdy,
Dialyzer [1] is a program that does CMUCL-like type inference on
Erlang programs to report discrepencies (like a linter). They just
posted [2] some code on the Erlang mailing list that the Dialyzer had
found a bug in and for fun I transliterated it [3] into Lisp to see if
CMUCL would find the bug too. Out of the box it did not but I'm
wondering if it could easily be made to.
Consider this simpler example:
(defun foo () (bar 1))
(defun bar (x) (symbol-value x))
Is there a way to make the compiler print a note that, with the
definitions in this file, foo's call to bar will always result in an
error?
The nearest way I know is with:
(defun foo () (bar 1))
(defun bar (x)
(declare (symbol x))
(symbol-value x))
but I'm hoping there's a way to tell the compiler: I want maximum
linting of this code, so please propagate inferred types between
functions, even though the functions could change independently.
Doable?
NB: I realise that you shouldn't do this in Lisp in general. In Erlang
it's okay to propagate types between module-internal functions because
you can only redefine whole modules and not individual functions.
[1]: Dialyzer,
http://www.it.uu.se/research/group/hipe/dialyzer/
[2]: Erlang code,
http://www.erlang.org/ml-archive/erlang-questions/200503/msg00238.html
[3]: Lisp version (with added type declarations),
http://fresh.homeunix.net/~luke/misc/lisp/xx.lisp