Any further attempt I've made to reduce the test case caused the bug to disappear.
The failure appears to be that CONSTRAIN-REF-TYPE calls CHANGE-REF-LEAF to alter the A referred to in (G A) to be NUMBER (from the LET-converted inline-expansion of MOD). This leads to the toplevel lambda attempting to CLOSE-OVER a variable from a lambda that is not part of its lexical environment.
A slightly more minimal test case:
#'(lambda (a)
#'(lambda (e)
(return- from :block (f (mod a e))))
(if (let ((s a))
(block :block
(map nil
s)))
(g a)))
Any further attempt I've made to reduce the test case caused the bug to disappear.
The failure appears to be that CONSTRAIN-REF-TYPE calls CHANGE-REF-LEAF to alter the A referred to in (G A) to be NUMBER (from the LET-converted inline-expansion of MOD). This leads to the toplevel lambda attempting to CLOSE-OVER a variable from a lambda that is not part of its lexical environment.