diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2012-05-29 10:28:02 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2012-05-29 10:28:02 -0400 |
commit | 6876a58db34b81e411293b5ee8d161aa451fd767 (patch) | |
tree | b1cc081fe4c2b62f737018f19c016b95ff5a9e99 /lisp/emacs-lisp/pcase.el | |
parent | 46b7967e4d98570501f5e75ba7460fa4c79e4617 (diff) | |
download | emacs-6876a58db34b81e411293b5ee8d161aa451fd767.tar.gz emacs-6876a58db34b81e411293b5ee8d161aa451fd767.tar.bz2 emacs-6876a58db34b81e411293b5ee8d161aa451fd767.zip |
Fix minor corner case bugs in byte compilation and pcase.
* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand): Don't re-preprocess
functions from byte-compile-function-environment.
* lisp/emacs-lisp/bytecomp.el (byte-compile-constp): Treat #'v as a constant.
(byte-compile-close-variables): Bind byte-compile--outbuffer here...
(byte-compile-from-buffer): ...rather than here.
* lisp/emacs-lisp/pcase.el (pcase--expand): Accept different sets of vars in
different alternative patterns.
(pcase-codegen): Be more careful to preserve identity.
(pcase--u1): Don't forget to mark vars as used.
Diffstat (limited to 'lisp/emacs-lisp/pcase.el')
-rw-r--r-- | lisp/emacs-lisp/pcase.el | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 363c0965c3e..9f98b30adae 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -206,9 +206,12 @@ of the form (UPAT EXP)." (setq vars (delq v vars)) (cdr v))) prevvars))) - (when vars ;New additional vars. - (error "The vars %s are only bound in some paths" - (mapcar #'car vars))) + ;; If some of `vars' were not found in `prevvars', that's + ;; OK it just means those vars aren't present in all + ;; branches, so they can be used within the pattern + ;; (e.g. by a `guard/let/pred') but not in the branch. + ;; FIXME: But if some of `prevvars' are not in `vars' we + ;; should remove them from `prevvars'! `(funcall ,res ,@args))))))) (main (pcase--u @@ -225,7 +228,10 @@ of the form (UPAT EXP)." (pcase--let* defs main)))) (defun pcase-codegen (code vars) - `(let* ,(mapcar (lambda (b) (list (car b) (cdr b))) vars) + ;; Don't use let*, otherwise pcase--let* may merge it with some surrounding + ;; let* which might prevent the setcar/setcdr in pcase--expand's fancy + ;; codegen from later metamorphosing this let into a funcall. + `(let ,(mapcar (lambda (b) (list (car b) (cdr b))) vars) ,@code)) (defun pcase--small-branch-p (code) @@ -619,6 +625,7 @@ Otherwise, it defers to REST which is a list of branches of the form sym (apply-partially #'pcase--split-member elems) rest)) (then-rest (car splitrest)) (else-rest (cdr splitrest))) + (put sym 'pcase-used t) (pcase--if `(,(if memq-fine #'memq #'member) ,sym ',elems) (pcase--u1 matches code vars then-rest) (pcase--u else-rest))) |