* bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions
@ 2023-04-19 22:15 Thuna
2023-04-20 6:50 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Thuna @ 2023-04-19 22:15 UTC (permalink / raw)
To: 62959
[-- Attachment #1: Type: text/plain, Size: 642 bytes --]
The function `eieio--known-slot-name-p' is used by some eieio functions
(specifically eieio-oref, eieio-oref-default, and eieio-oset-default) to
check whether a slot name is known or not, and if not signals an
"Unknown slot" warning.
Structs do not make their slots known to `eieio--known-slot-name-p', so
the warning is signaled even for valid slot names. Since eieio aims for
compatibility with defstruct, this should probably be considered a bug.
The function `eieio--known-slot-name-p' checks the variable
`eieio--known-slot-names' but also has a fallback for the name's
`slot-name' property. In the patch I opted to use the latter.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: The patch --]
[-- Type: text/x-patch, Size: 1042 bytes --]
From 86ed1ed7d024a0d40286d5fe4697258dc98a1b9e Mon Sep 17 00:00:00 2001
From: Thuna <thuna.cing@gmail.com>
Date: Wed, 19 Apr 2023 23:43:22 +0200
Subject: [PATCH] Recognize defstruct slot names in various eieio functions
* lisp/emacs-lisp/cl-preloaded.el (cl-struct-define): Set each slot's
name's `slot-name' property so that `eieio--known-slot-name-p' can
recognize them.
---
lisp/emacs-lisp/cl-preloaded.el | 1 +
1 file changed, 1 insertion(+)
diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el
index 9445093f143..5235be52996 100644
--- a/lisp/emacs-lisp/cl-preloaded.el
+++ b/lisp/emacs-lisp/cl-preloaded.el
@@ -176,6 +176,7 @@ cl-struct-define
(i 0)
(offset (if type 0 1)))
(dolist (slot slots)
+ (put (car slot) 'slot-name t)
(let* ((props (cl--plist-to-alist (cddr slot)))
(typep (assq :type props))
(type (if (null typep) t
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions
2023-04-19 22:15 bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions Thuna
@ 2023-04-20 6:50 ` Eli Zaretskii
2023-05-02 20:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2023-04-20 6:50 UTC (permalink / raw)
To: Thuna, Stefan Monnier; +Cc: 62959
> From: Thuna <thuna.cing@gmail.com>
> Date: Thu, 20 Apr 2023 00:15:50 +0200
>
> The function `eieio--known-slot-name-p' is used by some eieio functions
> (specifically eieio-oref, eieio-oref-default, and eieio-oset-default) to
> check whether a slot name is known or not, and if not signals an
> "Unknown slot" warning.
>
> Structs do not make their slots known to `eieio--known-slot-name-p', so
> the warning is signaled even for valid slot names. Since eieio aims for
> compatibility with defstruct, this should probably be considered a bug.
>
> The function `eieio--known-slot-name-p' checks the variable
> `eieio--known-slot-names' but also has a fallback for the name's
> `slot-name' property. In the patch I opted to use the latter.
>
>
> >From 86ed1ed7d024a0d40286d5fe4697258dc98a1b9e Mon Sep 17 00:00:00 2001
> From: Thuna <thuna.cing@gmail.com>
> Date: Wed, 19 Apr 2023 23:43:22 +0200
> Subject: [PATCH] Recognize defstruct slot names in various eieio functions
>
> * lisp/emacs-lisp/cl-preloaded.el (cl-struct-define): Set each slot's
> name's `slot-name' property so that `eieio--known-slot-name-p' can
> recognize them.
> ---
> lisp/emacs-lisp/cl-preloaded.el | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el
> index 9445093f143..5235be52996 100644
> --- a/lisp/emacs-lisp/cl-preloaded.el
> +++ b/lisp/emacs-lisp/cl-preloaded.el
> @@ -176,6 +176,7 @@ cl-struct-define
> (i 0)
> (offset (if type 0 1)))
> (dolist (slot slots)
> + (put (car slot) 'slot-name t)
> (let* ((props (cl--plist-to-alist (cddr slot)))
> (typep (assq :type props))
> (type (if (null typep) t
> --
> 2.39.2
>
Stefan, any comments?
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions
2023-04-20 6:50 ` Eli Zaretskii
@ 2023-05-02 20:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-03 11:47 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-05-02 20:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 62959, Thuna
>> diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el
>> index 9445093f143..5235be52996 100644
>> --- a/lisp/emacs-lisp/cl-preloaded.el
>> +++ b/lisp/emacs-lisp/cl-preloaded.el
>> @@ -176,6 +176,7 @@ cl-struct-define
>> (i 0)
>> (offset (if type 0 1)))
>> (dolist (slot slots)
>> + (put (car slot) 'slot-name t)
>> (let* ((props (cl--plist-to-alist (cddr slot)))
>> (typep (assq :type props))
>> (type (if (null typep) t
>> --
>> 2.39.2
>>
>
> Stefan, any comments?
LGTM, thanks,
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions
2023-05-02 20:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-05-03 11:47 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-05-03 11:47 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 62959-done, thuna.cing
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Thuna <thuna.cing@gmail.com>, 62959@debbugs.gnu.org
> Date: Tue, 02 May 2023 16:48:02 -0400
>
> >> diff --git a/lisp/emacs-lisp/cl-preloaded.el b/lisp/emacs-lisp/cl-preloaded.el
> >> index 9445093f143..5235be52996 100644
> >> --- a/lisp/emacs-lisp/cl-preloaded.el
> >> +++ b/lisp/emacs-lisp/cl-preloaded.el
> >> @@ -176,6 +176,7 @@ cl-struct-define
> >> (i 0)
> >> (offset (if type 0 1)))
> >> (dolist (slot slots)
> >> + (put (car slot) 'slot-name t)
> >> (let* ((props (cl--plist-to-alist (cddr slot)))
> >> (typep (assq :type props))
> >> (type (if (null typep) t
> >> --
> >> 2.39.2
> >>
> >
> > Stefan, any comments?
>
> LGTM, thanks,
Thanks, installed on the emacs-29 branch, and closing.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-03 11:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-19 22:15 bug#62959: [PATCH] Recognize defstruct slot names in various eieio functions Thuna
2023-04-20 6:50 ` Eli Zaretskii
2023-05-02 20:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-03 11:47 ` Eli Zaretskii
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).