* 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.
This commit is contained in:
Stefan Monnier 2021-03-09 11:04:03 -05:00
parent 40d8f83e53
commit 7561c01380
2 changed files with 8 additions and 2 deletions

View file

@ -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)))

View file

@ -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: