From 7561c01380aa3347901eeddd2d0a466cb29ebbd8 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 9 Mar 2021 11:04:03 -0500 Subject: [PATCH] * lisp/emacs-lisp/cconv.el: Don't confuse a string for a docstring (cconv--convert-funcbody): Check there's something after a docstring. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-string-vs-docstring): New corresponding test. --- lisp/emacs-lisp/cconv.el | 5 +++-- test/lisp/emacs-lisp/bytecomp-tests.el | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el index bd0a3e87e64..68e930fa3f5 100644 --- a/lisp/emacs-lisp/cconv.el +++ b/lisp/emacs-lisp/cconv.el @@ -295,8 +295,9 @@ of converted forms." (if wrappers (let ((special-forms '())) ;; Keep special forms at the beginning of the body. - (while (or (stringp (car funcbody)) ;docstring. - (memq (car-safe (car funcbody)) '(interactive declare))) + (while (or (and (cdr funcbody) (stringp (car funcbody))) ;docstring. + (memq (car-safe (car funcbody)) + '(interactive declare :documentation))) (push (pop funcbody) special-forms)) (let ((body (macroexp-progn funcbody))) (dolist (wrapper wrappers) (setq body (funcall wrapper body))) diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 03c267ccd0f..5147cd26883 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1222,6 +1222,11 @@ compiled correctly." (byte-compile 'counter) (should (equal (counter) 1)))))) +(ert-deftest bytecomp-string-vs-docstring () + ;; Don't confuse a string return value for a docstring. + (let ((lexical-binding t)) + (should (equal (funcall (byte-compile '(lambda (x) "foo")) 'dummy) "foo")))) + ;; Local Variables: ;; no-byte-compile: t ;; End: -- 2.39.2