Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cl-generic.el: lexical-let patch for method dispatch lambdas
This patch serves to ensure that the following code will complete without error, returning an expected value from the 'frob' method specialized on the class 'b' ~~~~ (require 'eieio) (defclass a () ()) (defclass b (a) ()) (cl-defgeneric frob (obj) (:method ((obj a)) (list :a obj)) (:method ((obj b)) (append (when (cl-next-method-p) (cl-call-next-method)) (list :b)))) (frob (b)) ;; => (:a #s(b) :b) ~~~~ Previously, there were unbound symbols in anonymous lambda forms initialized for dispatch in the method call. An excerpt from the backtrace on the method call for `(frob (b))` with the unpatched source: ~~~~ (apply #'(lambda (cl--nmp cl--cnm obj) (progn (append (if (funcall cl--nmp) (progn (funcall cl--cnm))) (list :b)))) cl--nmp cl--cnm cl--args) (let ((cl--cnm #'(lambda (&rest args) (apply cl--nm (or args cl--args))))) (apply #'(lambda (cl--nmp cl--cnm obj) (progn (append (if (funcall cl--nmp) (progn ...)) (list :b)))) cl--nmp cl--cnm cl--args)) (lambda (&rest cl--args) "\n\n(fn OBJ)" (let ((cl--cnm #'(lambda (&rest args) (apply cl--nm ...)))) (apply #'(lambda (cl--nmp cl--cnm obj) (progn (append ... ...))) cl--nmp cl--cnm cl--args)))(#<b b-2083ca3bc>) apply((lambda (&rest cl--args) "\n\n(fn OBJ)" (let ((cl--cnm #'(lambda (&rest args) (apply cl--nm ...)))) (apply #'(lambda (cl--nmp cl--cnm obj) (progn (append ... ...))) cl--nmp cl--cnm cl--args))) #<b b-2083ca3bc> nil) frob(#<b b-2083ca3bc>) ~~~~ This patch establishes a lexical binding for variables that must be accessible in some encapsulated lambda form in the initial method call. This patch has been tested with GNU Emacs 29.0.50 built from the FreeBSD port editors/emacs-devel version 29.0.50.20220515,2 with the NATIVECOMP option enabled in the Emacs build.
- Loading branch information