]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix condition-case optimiser bug
authorMattias Engdegård <mattiase@acm.org>
Fri, 9 Apr 2021 16:59:09 +0000 (18:59 +0200)
committerMattias Engdegård <mattiase@acm.org>
Fri, 9 Apr 2021 17:20:55 +0000 (19:20 +0200)
* 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.

lisp/emacs-lisp/byte-opt.el
test/lisp/emacs-lisp/bytecomp-tests.el

index db8d825cfec7962c1e2ef0d29fee6fd8f0666be0..e52653753145c6eb4cdc2f9852489c4ec05827e1 100644 (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)
index 1953878d6f5ab368f472a5b8a398daedf690714e..94e33a7770e8a23b389094730d1ae05395d8db21 100644 (file)
 
     (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.")