From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#69387: 30.0.50; A string shouldn't be both a docstring and a return value Date: Mon, 4 Mar 2024 15:28:51 +0100 Message-ID: References: <2D08AD76-59F7-41BE-9363-96677967034A@gmail.com> <4FCE8B7D-17D7-44E8-A764-A6047209CBE1@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_E74424E4-0464-4646-82E7-447859B14709" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5998"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Philip Kaludercic , Eli Zaretskii , 69387@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 04 15:31:08 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rh9LH-0001Dx-Tp for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Mar 2024 15:31:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rh9Ku-0000GJ-RM; Mon, 04 Mar 2024 09:30:37 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rh9Kq-0000FL-Pq for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 09:30:32 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rh9Kq-0003Hd-Gy for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 09:30:32 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rh9LK-0007MP-3v for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 09:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Mar 2024 14:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69387 X-GNU-PR-Package: emacs Original-Received: via spool by 69387-submit@debbugs.gnu.org id=B69387.170956263328241 (code B ref 69387); Mon, 04 Mar 2024 14:31:02 +0000 Original-Received: (at 69387) by debbugs.gnu.org; 4 Mar 2024 14:30:33 +0000 Original-Received: from localhost ([127.0.0.1]:42644 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rh9Kq-0007LQ-If for submit@debbugs.gnu.org; Mon, 04 Mar 2024 09:30:32 -0500 Original-Received: from mail-lf1-f41.google.com ([209.85.167.41]:43178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rh9Kn-0007L4-EA for 69387@debbugs.gnu.org; Mon, 04 Mar 2024 09:30:30 -0500 Original-Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-51331634948so2652669e87.0 for <69387@debbugs.gnu.org>; Mon, 04 Mar 2024 06:29:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709562534; x=1710167334; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=03yPSDOUgG8CclvHN1p5DpfFt0Woy8NgOT/WMmycl40=; b=ceVYERS8ApBcbPMnv7Hqlh1vskwls7rPxB8VFDcgc7ChxO1EvS3C2qMapgsSS665dM 6XHSHqttXjGP15w2WVhDgKZyYMJzt1fVqDJ84L9k+L6bHfQynglx4xZNlfhfvbMjVjk0 3/EIMkOojWzF0c2jF4o/QUuYf9ffDTXJwvKL1sw/TT6/Nr26bZju60PPTureMBjzVUNf nej+d0nINLN1YgKJMf/gyoLplW5Zds3RiZnlK7SI2wRxPuajvPcRfFl/W31XwR4Qm3wD 1ZxPMQ75a1HOokmIju0M1KbiUov4PNlMHR47d0mnB4oJl2niQ/XAQjN6B24y+/9icjfE jkAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709562534; x=1710167334; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=03yPSDOUgG8CclvHN1p5DpfFt0Woy8NgOT/WMmycl40=; b=OuvKooTian6HJJa0ke3gk+MKynftzgk3+tK271YcgVh1PCqSvtMi2PsQCGMehMsfVm qQ7uelTY2Y7VGcc3LAjcUr+qYjpWxX0CJGgD/fWr5u5ZmVA6ROqSF/eOV/MEY/oHvkJT fdueDEVv0/ZPlMzx0uZsiOpJ6fgvhZzFM8U/DvcjDCqAVQFlx2lidnEbtbMpNm4l7SLd ipvy0ZRK8ytH9z87WqTVVlh93QOs2WYLkDEIDbMTNGq0FdmUNXDM1ls5h+PuxXZaVDUX e8ydUUu2TqnUVf7114M2IB9mz7Jbo351jzxge6uwWJPUcMVSRO7YaOMtnZiqNG2iVjBR DZFg== X-Forwarded-Encrypted: i=1; AJvYcCWhHWsEdLaC+B4gpbyNDppgnBF4H49ukZs6gKGNpjjT4uYgf0uGQKJSTm19Gw7DznNcdK0xi5Z0Ssetbi3DMIGI254p678= X-Gm-Message-State: AOJu0Yw/eNJrfkZKYiAjeWBF34FAT8+Ihr8f58Hdk2lgcCey21jkYwUo ywp65ZrDDMuV7X5JoipPGLTqYLoc+wRZbBu4dIEdUjbiDzllks+U X-Google-Smtp-Source: AGHT+IFArI68QIixL+RQ/IPoXfGJfscqchWG/sHljXbMXPwRUZeoRoo7WBNlI2NOZa5FCs0mArYIBw== X-Received: by 2002:a05:6512:3b9c:b0:513:1551:eb with SMTP id g28-20020a0565123b9c00b00513155100ebmr5486659lfv.3.1709562533454; Mon, 04 Mar 2024 06:28:53 -0800 (PST) Original-Received: from smtpclient.apple (c80-217-1-132.bredband.tele2.se. [80.217.1.132]) by smtp.gmail.com with ESMTPSA id d13-20020a19384d000000b005134de41180sm84282lfj.157.2024.03.04.06.28.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2024 06:28:53 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281009 Archived-At: --Apple-Mail=_E74424E4-0464-4646-82E7-447859B14709 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > I agree. I'll make a patch for the warning, just so that we can see = what it would look like. Here, belatedly. It includes the lambda string change. The warning = includes `defun` and `defmacro` but not plain lambdas. Removing doc strings from ambiguous lambdas didn't break anything, as = expected. I think the warning makes sense, because it does expose some = mistakes where doc strings were returned but shouldn't be, or returned = strings also exposed as (nonsensical) doc strings. There are quite a few cl-defmethod forms with this syndrome but those = definitions never were ambiguous (the strings are always a return = value, never doc string). --Apple-Mail=_E74424E4-0464-4646-82E7-447859B14709 Content-Disposition: attachment; filename=docstring-result-w.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="docstring-result-w.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index cc176821026..42a25bcc0aa 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -263,6 +263,11 @@ 'byte-run--set-no-font-lock-keyword (defalias 'byte-run--parse-body #'(lambda (body allow-interactive) "Decompose BODY into (DOCSTRING DECLARE INTERACTIVE BODY-REST WARNINGS)." + (if (and (null (cdr body)) (stringp (car body))) + (list nil nil nil body + (list (macroexp-warn-and-return + "Single string treated as return value, not doc string" + nil nil t body))) (let* ((top body) (docstring nil) (declare-form nil) @@ -305,7 +310,7 @@ 'byte-run--parse-body (t (setq interactive-form form))) t)))) (setq body (cdr body))) - (list docstring declare-form interactive-form body warnings)))) + (list docstring declare-form interactive-form body warnings))))) (defalias 'byte-run--parse-declarations #'(lambda (name arglist clauses construct declarations-alist) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index c3355eedd75..cf0e6d600dd 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3061,12 +3061,11 @@ byte-compile-lambda (append (if (not lexical-binding) arglistvars) byte-compile-bound-variables)) (body (cdr (cdr fun))) - (doc (if (stringp (car body)) + ;; Treat a final string literal as a value, not a doc string. + (doc (if (and (cdr body) (stringp (car body))) (prog1 (car body) - ;; Discard the doc string from the body - ;; unless it is the last element of the body. - (if (cdr body) - (setq body (cdr body)))))) + ;; Discard the doc string from the body. + (setq body (cdr body))))) (int (assq 'interactive body)) command-modes) (when lexical-binding --Apple-Mail=_E74424E4-0464-4646-82E7-447859B14709--