Fix condition-case optimiser bug

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't
perform incorrect optimisations when a condition-case variable shadows
another lexical variable.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
New test case.
This commit is contained in:
Mattias Engdegård 2021-04-09 18:59:09 +02:00
parent b7a7e879d0
commit 59342f689e
2 changed files with 14 additions and 2 deletions

View file

@ -528,8 +528,14 @@ Same format as `byte-optimize--lexvars', with shared structure and contents.")
`(condition-case ,var ;Not evaluated.
,(byte-optimize-form exp for-effect)
,@(mapcar (lambda (clause)
`(,(car clause)
,@(byte-optimize-body (cdr clause) for-effect)))
(let ((byte-optimize--lexvars
(and lexical-binding
(if var
(cons (list var t)
byte-optimize--lexvars)
byte-optimize--lexvars))))
(cons (car clause)
(byte-optimize-body (cdr clause) for-effect))))
clauses))))
(`(unwind-protect ,exp . ,exps)

View file

@ -431,6 +431,12 @@
(let ((x 2))
(list (or (bytecomp-test-identity 'a) (setq x 3)) x))
(let* ((x 1)
(y (condition-case x
(/ 1 0)
(arith-error x))))
(list x y))
)
"List of expressions for cross-testing interpreted and compiled code.")