I can reproduce back to 24.3 (which is the earliest Emacs I have running). I expect the bug has been present since the introduction of lexical scope. Looks somewhat similar to Bug#24171.