unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* setq's with missing final arguments.
@ 2015-11-22 12:26 Alan Mackenzie
  2015-11-22 12:31 ` David Kastrup
                   ` (4 more replies)
  0 siblings, 5 replies; 23+ messages in thread
From: Alan Mackenzie @ 2015-11-22 12:26 UTC (permalink / raw)
  To: emacs-devel

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).



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

end of thread, other threads:[~2015-11-23 15:02 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-22 12:26 setq's with missing final arguments Alan Mackenzie
2015-11-22 12:31 ` David Kastrup
2015-11-22 12:35 ` Oleh Krehel
2015-11-22 12:44   ` Teemu Likonen
2015-11-22 15:53   ` multi-assignment setq [was: setq's with missing final arguments.] Drew Adams
2015-11-23  7:58     ` Oleh Krehel
2015-11-23 15:02       ` Drew Adams
2015-11-22 12:52 ` setq's with missing final arguments Andreas Schwab
2015-11-22 13:03   ` Artur Malabarba
2015-11-22 13:08   ` David Kastrup
2015-11-22 13:11     ` Andreas Schwab
2015-11-22 13:23       ` David Kastrup
2015-11-22 13:34         ` Andreas Schwab
2015-11-22 14:10           ` Alan Mackenzie
2015-11-22 15:44             ` Eli Zaretskii
2015-11-22 19:44               ` Alan Mackenzie
2015-11-23  1:36                 ` Drew Adams
2015-11-22 15:42 ` Johan Bockgård
2015-11-22 16:04   ` Drew Adams
2015-11-22 15:52 ` Drew Adams
2015-11-22 23:08   ` Alan Mackenzie
2015-11-22 23:20     ` John Wiegley
2015-11-23  1:54       ` Drew Adams

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).