all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ignacio Casso <ignaciocasso@hotmail.com>
To: 53938@debbugs.gnu.org
Subject: bug#53938: 27.2; Defining function that modifies cl-struct before defining cl-struct
Date: Fri, 11 Feb 2022 10:45:50 +0100	[thread overview]
Message-ID: <PAXPR06MB776018BFDD7C8C2F074DBA0FC6309@PAXPR06MB7760.eurprd06.prod.outlook.com> (raw)

Hello,

I've noticed a possible bug in Emacs.

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)
  (let* ((v struct)) (\(setf\ my-struct-name\) new-name v))
  change-name(#s(my-struct :name nil) "asdf")
  eval((change-name my-struct "asdf") nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

A more realistic example, which produces the same error:

(defun my-package-config ()
  (setf (package-struct-slot package-var) 'new-value))

(eval-after-load 'my-package '(my-package-config))

(cl-defstruct package-struct slot)

(defvar package-var (make-package-struct))

(provide 'my-package)

It does not work either if we use instead a form inside eval-after-load
instead of defining a function, as in this example:

(eval-after-load 'my-package '(setf (package-struct-slot package-var) 'new-value))

However, it does work if we do something like this:

(setq my-package-config '(setf (package-struct-slot package-var) 'new-value))

(eval-after-load 'my-package '(eval my-package-config))


I realize that this might be a design constraint given that this common
lisp feature is "emulated", but maybe it should be better documented or
produce more descriptive errors? It's a really uncommon case though, I
only encountered it trying to configure in a weird way mu4e which uses cl
structs.

Regards,

Ignacio


In GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20)
 of 2022-01-16 built on ignacio-IdeaPad-3-15ADA05
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.3 LTS





             reply	other threads:[~2022-02-11  9:45 UTC|newest]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAXPR06MB776018BFDD7C8C2F074DBA0FC6309@PAXPR06MB7760.eurprd06.prod.outlook.com \
    --to=ignaciocasso@hotmail.com \
    --cc=53938@debbugs.gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.