all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Subject: setq's with missing final arguments.
Date: Sun, 22 Nov 2015 12:26:57 +0000	[thread overview]
Message-ID: <20151122122657.GA2332@acm.fritz.box> (raw)

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	other threads:[~2015-11-22 12:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-22 12:26 Alan Mackenzie [this message]
2015-11-22 12:31 ` setq's with missing final arguments 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151122122657.GA2332@acm.fritz.box \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.