Bug in compiler: DEFUN + LET + FUNCTION
Describe the bug
(FUNCTION FOO)
is treated as a constant reference during compilation if there is a (DEFUN FOO ...)
form inside of the LET
.
Because of that a variable with a value #'FOO
is being substituted and thus such a variable can "magically change its value without being modified" if FOO
is redefined inside of the body of the LET
.
To Reproduce
In REPL:
(funcall (compile
nil
(lambda ()
(defun foo () 'old)
(let ((old-foo #'foo))
(format t "~a vs " (funcall old-foo))
(defun foo () 'new)
(format t "~a~%" (funcall old-foo))))))
; >> OLD vs NEW
Expected behavior
Should've printed "OLD vs OLD"
Desktop (please complete the following information):
- OS: Linux
- Version: 21e
Additional context
See also SBCL's bug which was inherited from CMUCL [ https://bugs.launchpad.net/sbcl/+bug/1653370 ]