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


Message #8 received at 53938 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Ignacio Casso <ignaciocasso <at> hotmail.com>
Cc: 53938 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#53938: 27.2; Defining function that modifies cl-struct
 before defining cl-struct
Date: Sat, 12 Feb 2022 07:55:46 +0100
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)
>
> (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.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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.