bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#73526: 31.0.50; [FR] warn about unreachable code


From: Eshel Yaron
Subject: bug#73526: 31.0.50; [FR] warn about unreachable code
Date: Sat, 28 Sep 2024 12:23:36 +0200

Feature request: warn about unreachable code in Emacs Lisp.

Unreachable code means Lisp forms that occur in positions that can never
be reached, so these forms are never evaluated.  The simplest cases of
unreachable code are code that is only evaluated after some form that
never returns (such no-return forms include signal and throw calls, as
well as while loops with a never-nil test).

Unreachable code often indicates a programmer mistake, and never
improves (or otherwise affects) the program's behavior in any way.
So it's helpful to warn about it.  Clang and Go provide such warnings,
for example.

Emacs sources include many occurrences of such unreachable code.
For example, in lisp/mail/uudecode.el we find:

--8<---------------cut here---------------start------------->8---
(cond
 (done)
 ((> 0 remain)
  (error "uucode line ends unexpectedly")
  (setq done t))   <---- Unreachable!
 ...)
--8<---------------cut here---------------end--------------->8---

In lisp/gnus/nndir.el we see an example of a clear mistake that produces
easily detectable unreachable code:

--8<---------------cut here---------------start------------->8---
(or err "No such file or directory: %s" nndir-directory)
                                        ^ <---- Unreachable!
--8<---------------cut here---------------end--------------->8---


Thanks,

Eshel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]