diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2024-03-06 12:03:06 +0100 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2024-03-07 13:47:53 +0100 |
commit | 61b2f5f96b1d9dfd2fd908e09fac0d4163049c42 (patch) | |
tree | e76095045e99141e287be64920502e053de5a787 /etc | |
parent | 8aabd835747297818d538cc16b3f53fcc1dd67f6 (diff) | |
download | emacs-61b2f5f96b1d9dfd2fd908e09fac0d4163049c42.tar.gz |
Single string literal in body is return value only, not doc string
A function or macro body consisting of a single string literal now only
uses it as a return value. Previously, it had the dual uses as return
value and doc string, which was never what the programmer wanted and
had some inconvenient consequences (bug#69387).
This change applies to `lambda`, `defun`, `defsubst` and `defmacro`
forms; most other defining forms already worked in the sensible way.
* lisp/emacs-lisp/bytecomp.el (byte-compile-lambda):
Don't use a lone string literal as doc string.
* test/lisp/emacs-lisp/bytecomp-resources/warn-wide-docstring-defun.el
(foo): Update docstring warning test.
* doc/lispref/functions.texi (Function Documentation): Update.
* etc/NEWS: Announce.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/NEWS | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -1818,6 +1818,22 @@ Tree-sitter conditionally sets 'forward-sexp-function' for major modes that have defined 'sexp' in 'treesit-thing-settings' to enable sexp-related motion commands. ++++ +** Returned strings are never docstrings. +Functions and macros whose bodies consist of a single string literal now +only return that string; it is not used as a docstring. Example: + + (defun sing-a-song () + "Sing a song.") + +The above function returns the string '"Sing a song."' but has no +docstring. Previously, that string was used as both a docstring and +return value, which was never what the programmer wanted. If you want +the string to be a docstring, add an explicit return value. + +This change applies to 'defun', 'defsubst', 'defmacro' and 'lambda' +forms; other defining forms such as 'cl-defun' already worked this way. + ** New or changed byte-compilation warnings --- |