From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.emacs.bugs Subject: bug#6376: 23.2; byte compile add-to-list report free variable Date: Tue, 08 Jun 2010 11:30:42 +1000 Message-ID: <87y6eqia4d.fsf@blah.blah> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1275962307 25472 80.91.229.12 (8 Jun 2010 01:58:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Jun 2010 01:58:27 +0000 (UTC) To: 6376@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 08 03:58:25 2010 connect(): No such file or directory Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OLo5A-0005j3-GW for geb-bug-gnu-emacs@m.gmane.org; Tue, 08 Jun 2010 03:58:25 +0200 Original-Received: from localhost ([127.0.0.1]:48033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLo59-00029o-TF for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Jun 2010 21:58:23 -0400 Original-Received: from [140.186.70.92] (port=34658 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLo4t-00024e-32 for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:58:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLo4r-0000Ca-W8 for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:58:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45103) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLo4r-0000CT-TW for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:58:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OLo2s-0007Ut-08; Mon, 07 Jun 2010 21:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kevin Ryde Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Jun 2010 01:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6376 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.127596211528806 (code B ref -1); Tue, 08 Jun 2010 01:56:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Jun 2010 01:55:15 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLo27-0007UZ-4H for submit@debbugs.gnu.org; Mon, 07 Jun 2010 21:55:15 -0400 Original-Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLo25-0007UU-Tr for submit@debbugs.gnu.org; Mon, 07 Jun 2010 21:55:14 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:36445) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OLo22-0003Ah-9Z for submit@debbugs.gnu.org; Mon, 07 Jun 2010 21:55:10 -0400 Original-Received: from [140.186.70.92] (port=52574 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLo20-0008PJ-Bm for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:55:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLo1y-0008Lj-PM for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:55:08 -0400 Original-Received: from mailout1-3.pacific.net.au ([61.8.2.210]:60410 helo=mailout1.pacific.net.au) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLo1y-0008LQ-1q for bug-gnu-emacs@gnu.org; Mon, 07 Jun 2010 21:55:06 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.2.163]) by mailout1.pacific.net.au (Postfix) with ESMTP id 83DE15A8649 for ; Tue, 8 Jun 2010 11:30:56 +1000 (EST) Original-Received: from blah.blah (ppp287C.dyn.pacific.net.au [61.8.40.124]) by mailproxy2.pacific.net.au (Postfix) with ESMTP id 879E127410 for ; Tue, 8 Jun 2010 11:30:55 +1000 (EST) Original-Received: from gg by blah.blah with local (Exim 4.71) (envelope-from ) id 1OLneM-0002dO-Sf for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2010 11:30:42 +1000 User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 07 Jun 2010 21:56:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:37594 Archived-At: I made a mistake with a variable name to add-to-list and wondered if the byte compiler might report (add-to-list 'nosuchvariable ...) as a free variable, similar to the report for (set 'nosuchvariable ...) The few lines below get the desired effect, but might be a bit rough. The separate check-assign is with a view to sharing among set, setq, set-default and maybe others. Something specific for add-to-list would be vaguely reasonable since it's a builtin, but it could be worth trying a general way to flag an arg number as the name of a variable either referenced or assigned. Something like that might also allow "function not known to be defined" for quoted symbol args to mapcar, sort, etc. I suppose this sort of thing might be analysed by elint instead or as well, but the byte compiler has good information about bindings available after macro expansion etc and it's much more often run than elint. (defun byte-compile-check-assign (symbol) (cond ((and (byte-compile-warning-enabled-p 'constants) (byte-compile-const-symbol-p symbol t)) (byte-compile-warn "variable assignment to constant `%s'" symbol)) ((and (byte-compile-warning-enabled-p 'free-vars) (not (memq symbol byte-compile-bound-variables)) (not (memq symbol byte-compile-free-assignments))) (byte-compile-warn "assignment to free variable `%s'" symbol) (push symbol byte-compile-free-assignments)))) (defun byte-compile-varsym1 (form) ;; arg 1 is a symbol which is the name of a variable which must be found ;; eg. (foo 'var ...) (cond ((eq 'quote (car-safe (nth 1 form))) (let ((var (car-safe (cdr (nth 1 form))))) (if (symbolp var) (byte-compile-check-assign var)))) ;; (add-to-list 'nil ...) reaches here as (add-to-list nil ...), ;; call the check so as to report nil as a constant ((null (nth 1 form)) (byte-compile-check-assign nil))) (byte-compile-normal-call form)) (byte-defop-compiler-1 add-to-list byte-compile-varsym1) (byte-defop-compiler-1 add-to-ordered-list byte-compile-varsym1) In GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-05-16 on raven, modified by Debian configured using `configure '--build' 'i486-linux-gnu' '--build' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS='' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_AU value of $XMODIFIERS: nil locale-coding-system: iso-latin-1-unix default enable-multibyte-characters: t