GNU bug report logs -
#35767
26.1; byte compiler lost warning about calling define-key with wrong number of arguments
Previous Next
Reported by: Alex Branham <alex.branham <at> gmail.com>
Date: Thu, 16 May 2019 21:25:01 UTC
Severity: normal
Tags: fixed, patch
Found in version 26.1
Fixed in version 26.3
Done: Noam Postavsky <npostavs <at> gmail.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35767 in the body.
You can then email your comments to 35767 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#35767
; Package
emacs
.
(Thu, 16 May 2019 21:25:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Alex Branham <alex.branham <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 16 May 2019 21:25:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Save a file with this line somewhere and call it foo.el:
(define-key "l" #'ignore)
Then call:
emacs -Q --eval "(setq byte-compile-error-on-warn t)" -batch -f batch-byte-compile foo.el
it _should_ emit an error since define-key gets called with the wrong
number of arguments. In Emacs 25.3, it does. In Emacs 26.1 and Emacs
built recently from git master, it does not.
Alex
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#35767
; Package
emacs
.
(Tue, 28 May 2019 01:00:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 35767 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
tags 35767 + patch
quit
Alex Branham <alex.branham <at> gmail.com> writes:
> (define-key "l" #'ignore)
>
> Then call:
>
> emacs -Q --eval "(setq byte-compile-error-on-warn t)" -batch -f batch-byte-compile foo.el
>
> it _should_ emit an error since define-key gets called with the wrong
> number of arguments. In Emacs 25.3, it does. In Emacs 26.1 and Emacs
> built recently from git master, it does not.
Specifically, Emacs 26+ doesn't warn about wrong number of arguments to
subrs. The fix seems simple enough to apply to emacs-26.
Minor caveat, some subrs (e.g., length) get warned about twice (with
slightly different wording each time), but this occurs in 25.3 as well,
so I guess it's acceptable:
Warning: ‘length’ called with 3 args, but requires 1
Warning: length called with 3 arguments, but accepts only 1
[0001-Warn-about-wrong-number-of-args-for-subrs-Bug-35767.patch (text/x-diff, inline)]
From 050b2bd3041d3d856dcb5ff6adfa75e8a63d8032 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Mon, 27 May 2019 20:36:41 -0400
Subject: [PATCH] Warn about wrong number of args for subrs (Bug#35767)
* lisp/emacs-lisp/bytecomp.el (byte-compile-callargs-warn): Don't
assume byte-compile-fdefinition will return non-nil.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-warn-wrong-args)
(bytecomp-warn-wrong-args-subr): New tests.
---
lisp/emacs-lisp/bytecomp.el | 2 +-
test/lisp/emacs-lisp/bytecomp-tests.el | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 9ea4179b68..72e81a653c 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1379,7 +1379,7 @@ (defun byte-compile-function-warn (f nargs def)
(defun byte-compile-callargs-warn (form)
(let* ((def (or (byte-compile-fdefinition (car form) nil)
(byte-compile-fdefinition (car form) t)))
- (sig (byte-compile--function-signature def))
+ (sig (byte-compile--function-signature (or def (car form))))
(ncall (length (cdr form))))
;; Check many or unevalled from subr-arity.
(if (and (cdr-safe sig)
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index bc28c5a6a0..c399f65b40 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -438,6 +438,20 @@ (ert-deftest bytecomp-tests--warnings ()
;; Should not warn that mt--test2 is not known to be defined.
(should-not (re-search-forward "my--test2" nil t))))
+(ert-deftest bytecomp-warn-wrong-args ()
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (let ((inhibit-read-only t)) (erase-buffer))
+ (byte-compile '(remq 1 2 3))
+ (ert-info ((buffer-string) :prefix "buffer: ")
+ (should (re-search-forward "remq.*3.*2")))))
+
+(ert-deftest bytecomp-warn-wrong-args-subr ()
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (let ((inhibit-read-only t)) (erase-buffer))
+ (byte-compile '(safe-length 1 2 3))
+ (ert-info ((buffer-string) :prefix "buffer: ")
+ (should (re-search-forward "safe-length.*3.*1")))))
+
(ert-deftest test-eager-load-macro-expansion ()
(test-byte-comp-compile-and-load nil
'(progn (defmacro abc (arg) 1) (defun def () (abc 2))))
--
2.11.0
Added tag(s) patch.
Request was from
Noam Postavsky <npostavs <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Tue, 28 May 2019 01:00:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#35767
; Package
emacs
.
(Thu, 30 May 2019 22:52:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 35767 <at> debbugs.gnu.org (full text, mbox):
tags 35767 fixed
close 35767 26.3
quit
> Subject: [PATCH] Warn about wrong number of args for subrs (Bug#35767)
>
> * lisp/emacs-lisp/bytecomp.el (byte-compile-callargs-warn): Don't
> assume byte-compile-fdefinition will return non-nil.
> * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-warn-wrong-args)
> (bytecomp-warn-wrong-args-subr): New tests.
Pushed to emacs-26.
134edc1036 2019-05-30T18:46:07-04:00 "Warn about wrong number of args for subrs (Bug#35767)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=134edc10367a8434167656e631865c85b5f10c42
Added tag(s) fixed.
Request was from
Noam Postavsky <npostavs <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 30 May 2019 22:52:03 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 26.3, send any further explanations to
35767 <at> debbugs.gnu.org and Alex Branham <alex.branham <at> gmail.com>
Request was from
Noam Postavsky <npostavs <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 30 May 2019 22:52:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 28 Jun 2019 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 303 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.