Subject: bug#55914: 28.1; Defining as dynamic an already lexical var

From: Hendrik Tews <[email-masked]>
Date: Sat, 11 Jun 2022 23:33:24 +0200

Hi,

evaluating

    (let ((test-var nil))
      (eval '(defvar test-var t "XXX")))

works fine in emacs 27 but fails in 28.1 with "Defining as
dynamic an already lexical var", similarly for defcustom instead
of defvar.

The elisp manual 28.1 says in 12.5 Defining Global Variables:

     If SYMBOL is already lexically bound (e.g., if the ‘defvar’ form
     occurs in a ‘let’ form with lexical binding enabled), then ‘defvar’
     sets the dynamic value.

>From this I would conclude that the error is a bug. Or did I
overlook something in the documentation?

(I noticed this problem because of failing tests for Proof
General with emacs 28, see
https://github.com/ProofGeneral/PG/issues/657. There, inside a
let binding a Coq file is opened, which causes the Coq instance
of Proof General to be loaded, which somewhere contained a
defcustom for the variable that was bound with let.)

Best regards,

Hendrik Tews