GNU bug report logs - #21701
25.0.50; ert explainer for equal can't handle negative numbers (work in 24.5)

Previous Next

Package: emacs;

Reported by: Anders Lindgren <andlind <at> gmail.com>

Date: Sun, 18 Oct 2015 08:58:01 UTC

Severity: normal

Found in version 25.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

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 21701 in the body.
You can then email your comments to 21701 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Sun, 18 Oct 2015 08:58:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Anders Lindgren <andlind <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 18 Oct 2015 08:58:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; ert explainer for equal can't handle negative numbers (work
 in 24.5)
Date: Sun, 18 Oct 2015 10:56:58 +0200
[Message part 1 (text/plain, inline)]
Steps to repeat, eval the following and run `ert'.

(ert-deftest bad-equal ()
  (should (equal 23 -50)))

Instead of a normal Ert error, the following is reported:

A bad-equal
    aborted

When placing the cursor on the error and press "d" (to run the test case in
the debugger), the following call stack is presented:

  apply(debug (error (wrong-type-argument characterp -50)))
  ert--run-test-debugger([cl-struct-ert--test-execution-info...
  #[128 "\301\300\"\207" [[cl-struct-ert--test-execution-info ...
  format("?%c" -50)
  ert--explain-format-atom(-50)
  ert--explain-equal-rec(23 -50)
  ert--explain-equal(23 -50)
  apply(ert--explain-equal (23 -50))
  (list :explanation (apply -explainer- args-1))

Clearly, the code is trying to print -50 as a character.

This worked in Emacs 24.5, where Ert reported:

F bad-equal
    (ert-test-failed
     ((should
       (equal 23 -50))
      :form
      (equal 23 -50)
      :value nil :explanation
      (different-atoms
       (23 "#x17" "?")
       (-50 "#x3fffffffffffffce"))))


Sincerely,
    Anders Lindgren


In GNU Emacs 25.0.50.158 (x86_64-apple-darwin14.5.0, NS appkit-1348.17
Version 10.10.5 (Build 14F27))
 of 2015-10-16
Repository revision: ff4798b8b493ba1ec51dcb1c59a11824865124b8
Windowing system distributor 'Apple', version 10.3.1348
Configured using:
 'configure --with-ns --without-dbus'

Configured features:
ACL ZLIB TOOLKIT_SCROLL_BARS NS

Important settings:
  value of $LC_CTYPE: UTF-8
  locale-coding-system: utf-8-unix

Major mode: ERT-Results

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
bad-equal
Ran 1 tests, 0 results were as expected, 1 unexpected
Running test bad-equal...
Entering debugger...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils pp cl-extra help-mode cl-macs gv
ert find-func ewoc easymenu debug cl-loaddefs pcase cl-lib time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel ns-win term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 89635 5963)
 (symbols 48 19436 0)
 (miscs 40 78 159)
 (strings 32 15385 4052)
 (string-bytes 1 463936)
 (vectors 16 12257)
 (vector-slots 8 415700 5035)
 (floats 8 162 183)
 (intervals 56 271 6)
 (buffers 976 14))
[Message part 2 (text/html, inline)]

Added indication that bug 21701 blocks19759 Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 18 Oct 2015 17:30:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 09:42:03 GMT) Full text and rfc822 format available.

Message #10 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: 21701 <at> debbugs.gnu.org
Subject: cl-typecase broken (was 25.0.50; ert explainer for equal can't handle
 negative numbers)
Date: Fri, 4 Dec 2015 10:41:59 +0100
[Message part 1 (text/plain, inline)]
I just realised that the underlying problem is a change to `cl-typecase'.
It treats -50 as a character.

(cl-typecase -50
  (character "A character")
  (fixnum "A fixnum")
  (t "Something else"))

Emacs 25 returns "A character" and emacs 24 "A fixnum".

    -- Anders
[Message part 2 (text/html, inline)]

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Fri, 04 Dec 2015 13:31:02 GMT) Full text and rfc822 format available.

Notification sent to Anders Lindgren <andlind <at> gmail.com>:
bug acknowledged by developer. (Fri, 04 Dec 2015 13:31:02 GMT) Full text and rfc822 format available.

Message #15 received at 21701-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Anders Lindgren <andlind <at> gmail.com>
Cc: 21701-done <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50;
 ert explainer for equal can't handle negative numbers)
Date: Fri, 04 Dec 2015 08:30:47 -0500
> I just realised that the underlying problem is a change to `cl-typecase'.
> It treats -50 as a character.
>
> (cl-typecase -50
>   (character "A character")
>   (fixnum "A fixnum")
>   (t "Something else"))
>
> Emacs 25 returns "A character" and emacs 24 "A fixnum".

I installed the patch below which should fix this.


        Stefan


diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 09d2d3f..c8aad3a 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2885,7 +2885,7 @@ cl--macroexp-fboundp
 (put 'real 'cl-deftype-satisfies #'numberp)
 (put 'fixnum 'cl-deftype-satisfies #'integerp)
 (put 'base-char 'cl-deftype-satisfies #'characterp)
-(put 'character 'cl-deftype-satisfies #'integerp)
+(put 'character 'cl-deftype-satisfies #'natnump)
 
 
 ;;;###autoload




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 15:42:02 GMT) Full text and rfc822 format available.

Message #18 received at 21701-done <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 21701-done <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50; ert explainer for equal
 can't handle negative numbers)
Date: Fri, 4 Dec 2015 16:41:46 +0100
[Message part 1 (text/plain, inline)]
Hi,

This should solve the immediate problem with negative numbers.

However, I gave this some though and realised that there is still a problem
with large numbers. For example:

(cl-typecase (+ (max-char) 1)
  (character "A character")
  (fixnum "A fixnum")
  (t "Something else"))

Returns "A character".

However, "(format "%c" (+ (max-char) 1))" raises the error
"(wrong-type-argument characterp 4194304)".

The question is if `cl-typecase', `format', and `characterp' should have
the same definition on what a character is. If not, then ERT must be
modified to handle this, e.g. by using `base-char' rather than `character'.

Personally, I would perfer if `character' would mean the same thing in all
contexts. I would suggest that we restore the old meaning of `character',
drop `base-char', and add a new type class, say `key-event', that could
include things like ?\M-\C-x.

    -- Anders

On Fri, Dec 4, 2015 at 2:30 PM, Stefan Monnier <monnier <at> iro.umontreal.ca>
wrote:

> > I just realised that the underlying problem is a change to `cl-typecase'.
> > It treats -50 as a character.
> >
> > (cl-typecase -50
> >   (character "A character")
> >   (fixnum "A fixnum")
> >   (t "Something else"))
> >
> > Emacs 25 returns "A character" and emacs 24 "A fixnum".
>
> I installed the patch below which should fix this.
>
>
>         Stefan
>
>
> diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
> index 09d2d3f..c8aad3a 100644
> --- a/lisp/emacs-lisp/cl-macs.el
> +++ b/lisp/emacs-lisp/cl-macs.el
> @@ -2885,7 +2885,7 @@ cl--macroexp-fboundp
>  (put 'real 'cl-deftype-satisfies #'numberp)
>  (put 'fixnum 'cl-deftype-satisfies #'integerp)
>  (put 'base-char 'cl-deftype-satisfies #'characterp)
> -(put 'character 'cl-deftype-satisfies #'integerp)
> +(put 'character 'cl-deftype-satisfies #'natnump)
>
>
>  ;;;###autoload
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 17:37:02 GMT) Full text and rfc822 format available.

Message #21 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Anders Lindgren <andlind <at> gmail.com>
Cc: 21701 <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50;
 ert explainer for equal can't handle negative numbers)
Date: Fri, 04 Dec 2015 12:36:55 -0500
> However, "(format "%c" (+ (max-char) 1))" raises the error

> The question is if `cl-typecase', `format', and `characterp' should have
> the same definition on what a character is.

characterp corresponds to `base-char', at least if we want cl-*
functions to follow the Common-Lisp semantics.

> If not, then ERT must be modified to handle this, e.g. by using
> `base-char' rather than `character'.

That's indeed what should be done if ERT needs this to be a plain
character that can inserted in a string.  Common-Lisp's `character'
includes not just characters but also "characters with modifiers" such
as ?\M-\H-é, which can't appear in a string and are rejected by
`characterp'.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 18:18:01 GMT) Full text and rfc822 format available.

Message #24 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Anders Lindgren <andlind <at> gmail.com>
Cc: 21701 <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50;
 ert explainer for equal can't handle negative numbers)
Date: Fri, 04 Dec 2015 13:17:16 -0500
> That's indeed what should be done if ERT needs this to be a plain
> character that can inserted in a string.  Common-Lisp's `character'
> includes not just characters but also "characters with modifiers" such
> as ?\M-\H-é, which can't appear in a string and are rejected by
> `characterp'.

I installed a patch which makes ERT use pcase over cl-typecase.
In most cases it doesn't make a big difference, but in a few spots, it
is cleaner because a subsequent cl-destructuring-bind can be merged into
it (and it got rid of those places where we used (member :foo)
as a type to just check equality, which is rather inefficient).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 19:43:01 GMT) Full text and rfc822 format available.

Message #27 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 21701 <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50; ert explainer for equal
 can't handle negative numbers)
Date: Fri, 4 Dec 2015 20:42:53 +0100
[Message part 1 (text/plain, inline)]
Hi!

I assumed that `characterp' and the `character' type class was connected in
Common Lisp. If they aren't I guess the current system makes sense.

I downloaded the ert changes and ran all my local tests and I haven't seen
any problems.

Thanks!

    -- Anders

On Fri, Dec 4, 2015 at 7:17 PM, Stefan Monnier <monnier <at> iro.umontreal.ca>
wrote:

> > That's indeed what should be done if ERT needs this to be a plain
> > character that can inserted in a string.  Common-Lisp's `character'
> > includes not just characters but also "characters with modifiers" such
> > as ?\M-\H-é, which can't appear in a string and are rejected by
> > `characterp'.
>
> I installed a patch which makes ERT use pcase over cl-typecase.
> In most cases it doesn't make a big difference, but in a few spots, it
> is cleaner because a subsequent cl-destructuring-bind can be merged into
> it (and it got rid of those places where we used (member :foo)
> as a type to just check equality, which is rather inefficient).
>
>
>         Stefan
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 21:09:01 GMT) Full text and rfc822 format available.

Message #30 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Anders Lindgren <andlind <at> gmail.com>, Stefan Monnier
 <monnier <at> iro.umontreal.ca>
Cc: 21701 <at> debbugs.gnu.org
Subject: RE: bug#21701: Fwd: cl-typecase broken (was 25.0.50; ert explainer
 for equal can't handle negative numbers)
Date: Fri, 4 Dec 2015 13:08:10 -0800 (PST)
[Message part 1 (text/plain, inline)]
A reasonable guess.It might make sense to add a note to the Elisp manual, in node `Character Type' or node `Character Codes' (where we talk about `characterp'), or both, to point out that Emacs Lisp characters are not the same as Common Lisp chars.

 

I assumed that `characterp' and the `character' type class was connected in Common Lisp. If they aren't I guess the current system makes sense.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 21:26:02 GMT) Full text and rfc822 format available.

Message #33 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Anders Lindgren <andlind <at> gmail.com>
Cc: 21701 <at> debbugs.gnu.org
Subject: Re: Fwd: cl-typecase broken (was 25.0.50;
 ert explainer for equal can't handle negative numbers)
Date: Fri, 04 Dec 2015 16:25:50 -0500
> I assumed that `characterp' and the `character' type class was connected in
> Common Lisp.

They are.  The CLHS says:

          (characterp object) ==  (typep object 'character)

In Elisp that would translate to

          (cl-characterp object) ==  (cl-typep object 'character)

But cl-lib does not define cl-characterp and Elisp defines characterp
differently than Common-Lisp.

> If they aren't I guess the current system makes sense.

I think the current system can't make complete sense, sadly, because of
such subtle incompatibility between Elisp and Common Lisp.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 21:33:01 GMT) Full text and rfc822 format available.

Message #36 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, Anders Lindgren
 <andlind <at> gmail.com>
Cc: 21701 <at> debbugs.gnu.org
Subject: RE: bug#21701: Fwd: cl-typecase broken (was 25.0.50; ert explainer
 for equal can't handle negative numbers)
Date: Fri, 4 Dec 2015 13:32:41 -0800 (PST)
> (cl-characterp object) ==  (cl-typep object 'character)
> 
> But cl-lib does not define cl-characterp

Perhaps it should.  And then the doc should point out
that in Emacs Lisp, `cl-characterp' != `characterp'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Fri, 04 Dec 2015 22:59:02 GMT) Full text and rfc822 format available.

Message #39 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 21701 <at> debbugs.gnu.org, Anders Lindgren <andlind <at> gmail.com>
Subject: Re: bug#21701: Fwd: cl-typecase broken (was 25.0.50;
 ert explainer for equal can't handle negative numbers)
Date: Fri, 04 Dec 2015 17:58:05 -0500
Stefan Monnier wrote:

> I installed a patch which makes ERT use pcase over cl-typecase.

This causes test failures.

http://hydra.nixos.org/build/28477383
http://hydra.nixos.org/build/28477383/log/raw


   FAILED  ert-test-equal-including-properties
   FAILED  ert-test-explain-equal
   FAILED  ert-test-explain-equal-improper-list
   FAILED  ert-test-explain-equal-string-properties
   FAILED  ert-test-plist-difference-explanation
   FAILED  ert-test-run-tests-interactively
   FAILED  ert-test-run-tests-interactively-2




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21701; Package emacs. (Sat, 05 Dec 2015 15:09:01 GMT) Full text and rfc822 format available.

Message #42 received at 21701 <at> debbugs.gnu.org (full text, mbox):

From: Anders Lindgren <andlind <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 21701 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#21701: Fwd: cl-typecase broken (was 25.0.50; ert explainer
 for equal can't handle negative numbers)
Date: Sat, 5 Dec 2015 16:08:23 +0100
[Message part 1 (text/plain, inline)]
Hi,

Two of the problems can be fixed with the attached patch.

The third, `ert-test-record-backtrace' in `ert-tests.el' seems to compare
backtrace output -- I haven't looked it as I have no idea what it is
supposed to test.

    -- Anders

On Fri, Dec 4, 2015 at 11:58 PM, Glenn Morris <rgm <at> gnu.org> wrote:

> Stefan Monnier wrote:
>
> > I installed a patch which makes ERT use pcase over cl-typecase.
>
> This causes test failures.
>
> http://hydra.nixos.org/build/28477383
> http://hydra.nixos.org/build/28477383/log/raw
>
>
>    FAILED  ert-test-equal-including-properties
>    FAILED  ert-test-explain-equal
>    FAILED  ert-test-explain-equal-improper-list
>    FAILED  ert-test-explain-equal-string-properties
>    FAILED  ert-test-plist-difference-explanation
>    FAILED  ert-test-run-tests-interactively
>    FAILED  ert-test-run-tests-interactively-2
>
[Message part 2 (text/html, inline)]
[ert.diff (text/plain, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 03 Jan 2016 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 166 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.