From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#24449: Emacs 25.1 RC2: Byte compiler reports error in wrong place. Date: Fri, 16 Sep 2016 18:34:51 +0000 Message-ID: <20160916183451.GE3630@acm.fritz.box> References: <20160916113124.GB3630@acm.fritz.box> <83wpic3rpb.fsf@gnu.org> <20160916133352.GC3630@acm.fritz.box> <83twdf51al.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1474050991 26380 195.159.176.226 (16 Sep 2016 18:36:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 16 Sep 2016 18:36:31 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: 24449@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Sep 16 20:36:28 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkxzm-0005TJ-Q2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 16 Sep 2016 20:36:18 +0200 Original-Received: from localhost ([::1]:43201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkxzk-0002hz-R7 for geb-bug-gnu-emacs@m.gmane.org; Fri, 16 Sep 2016 14:36:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkxzb-0002fk-Hc for bug-gnu-emacs@gnu.org; Fri, 16 Sep 2016 14:36:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkxzW-0001Ge-Ht for bug-gnu-emacs@gnu.org; Fri, 16 Sep 2016 14:36:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkxzW-0001GU-Ef for bug-gnu-emacs@gnu.org; Fri, 16 Sep 2016 14:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bkxzW-0005Cq-4a for bug-gnu-emacs@gnu.org; Fri, 16 Sep 2016 14:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Sep 2016 18:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24449 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24449-submit@debbugs.gnu.org id=B24449.147405092119964 (code B ref 24449); Fri, 16 Sep 2016 18:36:02 +0000 Original-Received: (at 24449) by debbugs.gnu.org; 16 Sep 2016 18:35:21 +0000 Original-Received: from localhost ([127.0.0.1]:33549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkxyq-0005Bw-UJ for submit@debbugs.gnu.org; Fri, 16 Sep 2016 14:35:21 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:15406) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkxyp-0005Bk-1A for 24449@debbugs.gnu.org; Fri, 16 Sep 2016 14:35:19 -0400 Original-Received: (qmail 41262 invoked by uid 3782); 16 Sep 2016 18:35:15 -0000 Original-Received: from acm.muc.de (p548C6AC0.dip0.t-ipconnect.de [84.140.106.192]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 16 Sep 2016 20:35:14 +0200 Original-Received: (qmail 14281 invoked by uid 1000); 16 Sep 2016 18:34:51 -0000 Content-Disposition: inline In-Reply-To: <83twdf51al.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:123389 Archived-At: On Fri, Sep 16, 2016 at 06:09:38PM +0300, Eli Zaretskii wrote: > > Date: Fri, 16 Sep 2016 13:33:52 +0000 > > Cc: 24449@debbugs.gnu.org > > From: Alan Mackenzie > > > > > If you didn't, you should, because after you do, you will never again > > > wonder why an incorrect line number is reported. In fact, now that I > > > did look there, I'm surprised it reports a correct line number at all, > > > let alone as often as it does. It's sheer luck. > > > > This is not a Good Thing. Even its own comment describes itself as a > > "gross hack". Surely we can do better? > I certainly hope we can. But, unless I misunderstood something, the > way it's designed makes that really hard. After studying `byte-compile-set-symbol-position' for several hours, I can now see what it's meant to do, and the bug that prevents it doing it. The variable `last' was intended to record the previous value of byte-compile-last-position to ensure that its next value would be higher than the previous one. Part of the comment was intended to express this. But in some sort of coding error, `last' ended up being set at each iteration of the loop, making it purposeless. By binding `last' to its intended value at the start of `b-c-set-symbol-position', and amending the loop condition to avoid an infinite loop, the warning message for the faulty cc-engine.el now comes out at the right place. I'm not sure my new version provides any guarantee of correctness either, but I think it's more likely. Here is my patch. I still think I should amend the comment preceding it. diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index b6bb1d6..2502323 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1042,19 +1042,20 @@ byte-compile-delete-first ;; gross hack? And the answer, of course, would be yes. (defun byte-compile-set-symbol-position (sym &optional allow-previous) (when byte-compile-read-position - (let (last entry) + (let ((last byte-compile-last-position) + entry) (while (progn - (setq last byte-compile-last-position - entry (assq sym read-symbol-positions-list)) + (setq entry (assq sym read-symbol-positions-list)) (when entry (setq byte-compile-last-position (+ byte-compile-read-position (cdr entry)) read-symbol-positions-list (byte-compile-delete-first entry read-symbol-positions-list))) - (or (and allow-previous - (not (= last byte-compile-last-position))) - (> last byte-compile-last-position))))))) + (and entry + (or (and allow-previous + (not (= last byte-compile-last-position))) + (> last byte-compile-last-position)))))))) (defvar byte-compile-last-warned-form nil) (defvar byte-compile-last-logged-file nil) Comments? -- Alan Mackenzie (Nuremberg, Germany).