emacs-devel
[Top][All Lists]
Advanced

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

setq's with missing final arguments.


From: Alan Mackenzie
Subject: setq's with missing final arguments.
Date: Sun, 22 Nov 2015 12:26:57 +0000
User-agent: Mutt/1.5.23 (2014-03-12)

Hello, Emacs.

Consider this file:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar foo t)
(defvar bar t)

(defun bad-setq ()
  "Doc string"
  (setq foo 5
        bar))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In the setq, there is a missing argument after "bar".  At the moment,
the byte compiler just generates code to assign nil to bar, without
giving any warning.  IMAO, this is Very Bad.

I propose to insert code into the byte compiler to detect and warn of
this scenario:



diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 3574364..1e75d48 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3739,7 +3739,11 @@ byte-compile-setq
   (let ((args (cdr form)))
     (if args
        (while args
-         (byte-compile-form (car (cdr args)))
+         (if (eq (length args) 1)
+              (byte-compile-warn
+               "implicit nil assignment to `%s'"
+               (prin1-to-string (car args))))
+          (byte-compile-form (car (cdr args)))
          (or byte-compile--for-effect (cdr (cdr args))
              (byte-compile-out 'byte-dup 0))
          (byte-compile-variable-set (car args))


Any objections?

Just as a matter of interest, I came across an actual instance of this
solecism in Emacs, where it is clearly an error.  For some reason, this
instance doesn't trigger an "implicit nil assignment" warning; perhaps
it is because it is inside a pcase.

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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