Subject: bug#76573: 30.1; native compilation fails for record inside function

From: Eli Zaretskii <[email-masked]>
Date: Sat, 26 Apr 2025 09:54:27 +0300

> From: Lin Jian <[email-masked]>
> Cc: [email-masked],  Eli Zaretskii <[email-masked]>
> Date: Sat, 26 Apr 2025 05:13:14 +0800
> 
> Andrea Corallo <[email-masked]> writes:
> 
> > > If using `record' directly is a user error, I would suggest:
> > > 1. mentioning it in the manual
> > We can always improve the manual (patches welcome)
> 
> It may not be a good idea for me to write such as patch since I do not
> know the inner workings of this topic.
> 
> > the docstring for 'record' already says:
> >
> > "(record TYPE &rest SLOTS)
> >
> > Create a new record.
> > TYPE is its type as returned by ‘type-of’."
> >
> > How can somebody expect this machinery to work reliably for a certain
> > type which was never defined?
> 
> Since "M-x eval-expression (type-of (record 'foo-r)) RET" works and how
> to define a type is not mentioned, users may not realize that they need
> to define a type first or they may think `record' will define the type
> for them when necessary.

Let's take a step back and revisit the original report:

  > emacs -Q --batch --eval="(native-compile (defun foo-f () (record 'foo-r)))"
  Error: error (foo-f "Type foo-r missing from typeof-types!")
    signal(error (foo-f "Type foo-r missing from typeof-types!"))
    comp--native-compile(foo-f nil nil)
    native-compile(foo-f)
    eval((native-compile (defun foo-f nil (record 'foo-r))) t)
    command-line-1(("--eval=(native-compile (defun foo-f () (record 'foo-r)))"))
    command-line()
    normal-top-level()
  peculiar error: "Type foo-r missing from typeof-types!"

The discussion that followed indicates that the compiler's error
message is accurate: the code attempts to use an undefined data type.
Thus, it sounds to me that Emacs is working as intended, and we should
close this non-bug.

I don't understand how you reach the conclusion that users might think
'record' creates a type, when the compiler says the type is undefined.

Maybe we should make the error message more clear, like

  Type foo-r is unknown or undefined!

Will this be an okay solution?