GNU bug report logs - #53938
27.2; Defining function that modifies cl-struct before defining cl-struct

Previous Next

Package: emacs;

Reported by: Ignacio Casso <ignaciocasso <at> hotmail.com>

Date: Fri, 11 Feb 2022 10:03:02 UTC

Severity: normal

Tags: moreinfo, notabug

Found in version 27.2

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Ignacio Casso <ignaciocasso <at> hotmail.com>, 53938 <at> debbugs.gnu.org
Subject: bug#53938: 27.2; Defining function that modifies cl-struct before defining cl-struct
Date: Sat, 12 Feb 2022 09:45:44 -0500
Lars Ingebrigtsen [2022-02-12 07:55:46] wrote:
> Ignacio Casso <ignaciocasso <at> hotmail.com> writes:
>> If you define a function that uses a cl struct before defining the cl
>> struct (e.g., because the struct is defined in a package to be autoloaded and the
>> function in your init file), there is an error when calling the function
>> later.
>>
>> Here is a simple elisp file to reproduce it, starting Emacs with "emacs
>> -Q":
>>
>> (require 'cl-macs)

Please require `cl-lib` rather than `cl-macs` here.

>> (defun change-name (struct new-name)
>>   (setf (my-struct-name struct) new-name))
>>
>> (cl-defstruct my-struct
>>   name)
>>
>> (setq my-struct (make-my-struct))
>>
>> (change-name my-struct "My struct")
>>
>> This produces the following error:
>>
>> Debugger entered--Lisp error: (void-function \(setf\ my-struct-name\))
>>   (\(setf\ my-struct-name\) new-name v)
>
> If you'd byte-compiled this, then the compiler would say
>
> In end of data:
> cl.el: Warning: the function ‘(setf my-struct-name)’ is not known to be
>     defined.
>
> So I think that Emacs is probably working as designed here.  But perhaps
> Stefan has some comments; added to the CCs.

Yes, it's working as designed (because the accessors are supposed to be
inlined).  OTOH, it should work like you want it if you pass
the :noinline option to `cl-defstruct`.


        Stefan





This bug report was last modified 3 years and 100 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.