Subject: Re: bug#67239: 30.0.50; 30.0.50: Error in nativecomp

From: Andrea Corallo <[email-masked]>
Date: Sat, 02 Dec 2023 04:44:03 -0500

Andrea Corallo <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Imran Khan <[email-masked]>
>>> Date: Fri, 17 Nov 2023 19:13:46 +0600
>>> 
>>> 
>>> Hello, I have come across a function that gives error when native
>>> compiled, but works fine when byte compiled.  The issue arose when using
>>> a third-party library (ts-format function in ts.el):
>>> 
>>> https://github.com/alphapapa/ts.el/blob/master/ts.el
>>> 
>>> But I have curved out the code so that you hopefully don't need to
>>> install that.
>>> 
>>> Reproduction under `emacs -Q`:
>>> 
>>> 1. First library "my-time.el" looks like:
>>> 
>>> ```
>>> ;;; -*- lexical-binding: t; -*-
>>> 
>>> (require 'cl-lib)
>>> 
>>> (cl-defstruct time
>>>   unix)
>>> 
>>> (defvar time-default-format "%Y-%m-%d %H:%M:%S %z"
>>>   "Default format for `time-format'.")
>>> 
>>> (defsubst time-format (&optional time-or-format-string time)
>>>   "Format timestamp with `format-time-string'.
>>> If TS-OR-FORMAT-STRING is a timestamp or nil, use the value of
>>> `time-default-format'.  If both TS-OR-FORMAT-STRING and TS are nil,
>>> use the current time."
>>>   (cl-etypecase time-or-format-string
>>>     (time (format-time-string time-default-format (time-unix time-or-format-string)))
>>>     (string (cl-etypecase time
>>>               (time (format-time-string time-or-format-string (time-unix time)))
>>>               (null (format-time-string time-or-format-string))))
>>>     (null (cl-etypecase time
>>>             (time (format-time-string time-default-format (time-unix time)))
>>>             (null (format-time-string time-default-format))))))
>>> 
>>> (provide 'my-time)
>>> ```
>>> 
>>> 2. Then there is my code "my-bug.el":
>>> 
>>> ```
>>> ;;; -*- lexical-binding: t -*-
>>> 
>>> (require 'my-time)
>>> 
>>> (defun my-bug ()
>>>   (let ((time (make-time :unix (time-convert (current-time) 'integer))))
>>>     ;; (message (time-format time)) ;; one argument works fine
>>>     (message (time-format "%F" time)) ;; but this says: (wrong-type-argument stringp time)
>>>     ))
>>> 
>>> (provide 'my-bug)
>>> ```
>>> 
>>> 3. When both of these are native compiled, doing `M-: (my-bug)` gives:
>>> ```
>>> Debugger entered--Lisp error: (wrong-type-argument stringp time)
>>>   my-bug()
>>>   eval-expression((my-bug) nil nil 127)
>>>   funcall-interactively(eval-expression (my-bug) nil nil 127)
>>>   command-execute(eval-expression)
>>> ```
>>> 
>>> 4. But if I C-M-x on `my-bug` manually, it works fine.
>>> 
>>> As far as I can tell, under 29.1 it worked fine under nativecomp too.
>>
>> Adding Andrea to the discussion.
>
> Thanks will look at.
>
>   Andrea

Quick update, didn't had much time and wans't trivial but I've a fix
that is under test.  I'll be pushing it when done.

Thanks

  Andrea