From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: setq's with missing final arguments. Date: Sun, 22 Nov 2015 12:26:57 +0000 Message-ID: <20151122122657.GA2332@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1448195129 6697 80.91.229.3 (22 Nov 2015 12:25:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 22 Nov 2015 12:25:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 22 13:25:21 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a0Thj-0001L1-1y for ged-emacs-devel@m.gmane.org; Sun, 22 Nov 2015 13:25:15 +0100 Original-Received: from localhost ([::1]:55710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0Thj-00055S-1d for ged-emacs-devel@m.gmane.org; Sun, 22 Nov 2015 07:25:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0ThW-000555-78 for emacs-devel@gnu.org; Sun, 22 Nov 2015 07:25:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0ThR-00019C-Ay for emacs-devel@gnu.org; Sun, 22 Nov 2015 07:25:02 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:60412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0ThR-000194-18 for emacs-devel@gnu.org; Sun, 22 Nov 2015 07:24:57 -0500 Original-Received: (qmail 44664 invoked by uid 3782); 22 Nov 2015 12:24:55 -0000 Original-Received: from acm.muc.de (p548A57CB.dip0.t-ipconnect.de [84.138.87.203]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 22 Nov 2015 13:24:54 +0100 Original-Received: (qmail 2403 invoked by uid 1000); 22 Nov 2015 12:26:57 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 193.149.48.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:194999 Archived-At: 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).