unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39385: Erroneous interaction of eval-when-compile and condition-case
@ 2020-02-01 21:47 Alan Mackenzie
  2020-02-02  1:04 ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2020-02-01 21:47 UTC (permalink / raw)
  To: 39385

Hello, Emacs.

On master, with emacs -Q.

Create the following file, bad-eval-when-compile.el:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmacro c-safe (&rest body)
  ;; safely execute BODY, return nil if an error occurred
  `(condition-case nil
       (progn ,@body)
     (error nil)))

(defmacro foo ()
  (error "This message should not be seen"))

(eval-when-compile
  (c-safe (foo)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Now do M-x byte-compile-file <CR> bad-eval-when-compile.el <CR>.  This
erroneously throws the error:

    This message should not be seen

.  This should have been caught by the condition-case generated by
(c-safe ...).

As a matter of interest, if eval-when-compile is replaced by
cc-eval-when-compile:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmacro cc-eval-when-compile (&rest body)
  `(eval-when-compile
    (eval '(progn ,@body))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

, then the compilation succeeds.  So it would appear that there is a bug
in the byte compiler's handling of eval-when-compile.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#39385: Erroneous interaction of eval-when-compile and condition-case
  2020-02-01 21:47 bug#39385: Erroneous interaction of eval-when-compile and condition-case Alan Mackenzie
@ 2020-02-02  1:04 ` Noam Postavsky
  2020-02-02 13:20   ` Alan Mackenzie
  2020-02-02 15:37   ` Alan Mackenzie
  0 siblings, 2 replies; 4+ messages in thread
From: Noam Postavsky @ 2020-02-02  1:04 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 39385

Alan Mackenzie <acm@muc.de> writes:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defmacro c-safe (&rest body)
>   ;; safely execute BODY, return nil if an error occurred
>   `(condition-case nil
>        (progn ,@body)
>      (error nil)))
>
> (defmacro foo ()
>   (error "This message should not be seen"))
>
> (eval-when-compile
>   (c-safe (foo)))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> Now do M-x byte-compile-file <CR> bad-eval-when-compile.el <CR>.  This
> erroneously throws the error:
>
>     This message should not be seen

The same happens without eval-when-compile.

> .  This should have been caught by the condition-case generated by
> (c-safe ...).

I don't think so, because the condition-case is in the code generated by
c-safe (because the condition-case is quoted), whereas the error is
signaled while generating the code (because the error call is not
quoted).





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#39385: Erroneous interaction of eval-when-compile and condition-case
  2020-02-02  1:04 ` Noam Postavsky
@ 2020-02-02 13:20   ` Alan Mackenzie
  2020-02-02 15:37   ` Alan Mackenzie
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2020-02-02 13:20 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 39385

Hello, Noam.

On Sat, Feb 01, 2020 at 20:04:11 -0500, Noam Postavsky wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> > (defmacro c-safe (&rest body)
> >   ;; safely execute BODY, return nil if an error occurred
> >   `(condition-case nil
> >        (progn ,@body)
> >      (error nil)))

> > (defmacro foo ()
> >   (error "This message should not be seen"))

> > (eval-when-compile
> >   (c-safe (foo)))
> > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> > Now do M-x byte-compile-file <CR> bad-eval-when-compile.el <CR>.  This
> > erroneously throws the error:

> >     This message should not be seen

> The same happens without eval-when-compile.

> > .  This should have been caught by the condition-case generated by
> > (c-safe ...).

> I don't think so, because the condition-case is in the code generated by
> c-safe (because the condition-case is quoted), whereas the error is
> signaled while generating the code (because the error call is not
> quoted).

Ah, I think I've got it.  The macro is being expanded before the
condition-case is active, and this is when it throws the error.

Thanks for the help.

I'll close this as notabug.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#39385: Erroneous interaction of eval-when-compile and condition-case
  2020-02-02  1:04 ` Noam Postavsky
  2020-02-02 13:20   ` Alan Mackenzie
@ 2020-02-02 15:37   ` Alan Mackenzie
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2020-02-02 15:37 UTC (permalink / raw)
  To: control; +Cc: 39385

tags 39385 notabug
close 39385
quit

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-02 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-01 21:47 bug#39385: Erroneous interaction of eval-when-compile and condition-case Alan Mackenzie
2020-02-02  1:04 ` Noam Postavsky
2020-02-02 13:20   ` Alan Mackenzie
2020-02-02 15:37   ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).