unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Xuan Wang <code@wangxuan.name>
To: 70063@debbugs.gnu.org
Subject: bug#70063: [PATCH] fix warning-suppress for list type "warning type"
Date: Thu, 28 Mar 2024 21:07:34 -0400	[thread overview]
Message-ID: <87zfuhu9pl.fsf@WX-Desktop.mail-host-address-is-not-set> (raw)

[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]

Tags: patch


Bug report:

In warnings.el, the function warning-suppress is supposed to save the
user's choice into variable warning-suppress-types or
warning-suppress-log-types.

The type of a warning can be a simple symbol, or a list of symbols in
the format of '(warning-type subtype subsubtype).

The change introduced by commit d5ee49c25c8f59ab17c40eebdf38a769c2f5588b
fixes the problem in situations where the warning type is a simple
symbol, but this commit's code saves wrong data if the warning type is a
list.

old behavior:
type              warning-suppress-types
pkg           ->    '((pkg))                  Correct
(pkg subtype) ->    '(((pkg subtype)))        Incorrect

Refer to the implementation of warning-suppress-p, an element in
warning-suppress-types must be a list of symbols, must not be a simple
symbol, and must not be a list of lists (if this is the case, nothing is
going to be matched).

How to reproduce the bug:

Use any script that can emit a warning type that is a list. Press the
button on the warning buffer to suppress the warning. Run the script and
emit the warning again; you will see the warning buffer pop up, so the
warning is not suppressed.

How this patch fix the bug:

Check if the "warning type" is a list using "consp" first. If the
warning type is a list, add it directly to warning-suppress-types.
Otherwise, use the old behavior, wrap it in a list, then add it to
warning-suppress-types.

new behavior:
type              warning-suppress-types
pkg           ->    '((pkg))                Correct
(pkg subtype) ->    '((pkg subtype))        Correct


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fix-warning-suppress-for-list-type-warning-type.patch --]
[-- Type: text/patch, Size: 2006 bytes --]

From 57084c8de073c8ca1e74b98ca67e08b88813c42e Mon Sep 17 00:00:00 2001
From: Xuan Wang <code@wangxuan.name>
Date: Thu, 28 Mar 2024 20:34:23 -0400
Subject: [PATCH] fix warning-suppress for list type "warning type"

Per the document of warning-suppress-types and the implementation of
warning-suppress-p, a warning type can be either a symbol or a list of
symbols. The old implementation can generate wrong
warning-suppress-types.

old behavior:
type              warning-suppress-types
pkg           ->    '((pkg))                  Correct
(pkg subtype) ->    '(((pkg subtype)))        Incorrect

Now we check whether type is a cons cell first. (Should not use listp
here as listp returns t for nil)

new behavior:
type              warning-suppress-types
pkg           ->    '((pkg))                Correct
(pkg subtype) ->    '((pkg subtype))        Correct
---
 lisp/emacs-lisp/warnings.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el
index 6c62a56e99c..8b43c6a8726 100644
--- a/lisp/emacs-lisp/warnings.el
+++ b/lisp/emacs-lisp/warnings.el
@@ -225,10 +225,14 @@ SUPPRESS-LIST is the list of kinds of warnings to suppress."
              (?q "quit and do nothing"))))
     (?y
      (customize-save-variable 'warning-suppress-log-types
-                              (cons (list type) warning-suppress-log-types)))
+                              (if (consp type)
+                                  (cons type warning-suppress-log-types)
+                                (cons (list type) warning-suppress-log-types))))
     (?n
      (customize-save-variable 'warning-suppress-types
-                              (cons (list type) warning-suppress-types)))
+                              (if (consp type)
+                                  (cons type warning-suppress-types)
+                                (cons (list type) warning-suppress-types))))
     (_ (message "Exiting"))))
 
 ;;;###autoload
-- 
2.34.1


             reply	other threads:[~2024-03-29  1:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  1:07 Xuan Wang [this message]
2024-03-31  9:10 ` bug#70063: [PATCH] fix warning-suppress for list type "warning type" Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zfuhu9pl.fsf@WX-Desktop.mail-host-address-is-not-set \
    --to=code@wangxuan.name \
    --cc=70063@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).