Subject: Re: bug#53938: 27.2; Defining function that modifies cl-struct before defining cl-struct

From: Lars Ingebrigtsen <[email-masked]>
Date: Sat, 12 Feb 2022 07:55:46 +0100

Ignacio Casso <[email-masked]> 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