unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Ignacio Casso <ignaciocasso@hotmail.com>, 53938@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	[thread overview]
Message-ID: <jwvwni0ywvh.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bkzc60b1.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 12 Feb 2022 07:55:46 +0100")

Lars Ingebrigtsen [2022-02-12 07:55:46] wrote:
> Ignacio Casso <ignaciocasso@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






  reply	other threads:[~2022-02-12 14:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11  9:45 bug#53938: 27.2; Defining function that modifies cl-struct before defining cl-struct Ignacio Casso
2022-02-12  6:55 ` Lars Ingebrigtsen
2022-02-12 14:45   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-02-13  8:22     ` Lars Ingebrigtsen

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=jwvwni0ywvh.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=53938@debbugs.gnu.org \
    --cc=ignaciocasso@hotmail.com \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /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).