Subject: [PATCH] fix warning-suppress for list type "warning type"
From: Xuan Wang <[email-masked]>
To: [email-masked]
Date: Thu, 28 Mar 2024 21:07:34 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

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

From 57084c8de073c8ca1e74b98ca67e08b88813c42e Mon Sep 17 00:00:00 2001
From: Xuan Wang <[email-masked]>
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