bugKawa - Bugs: bug #40077, Boolean logical `not` on float...

 
 

bug #40077: Boolean logical `not` on float number can result in ClassCastException

Submitter:  Matthieu Vachon <maoueh>
Submitted:  Sat 21 Sep 2013 05:55:26 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 24 Sep 2013 02:07:10 AM UTC, comment #2: 

I checked in fix and testcase - thanks.

This wasn't very obvious.  The problem was not the floating-point number, but that eqv? had the wrong return type: the generic Type.booleanType rather than the Scheme-appropriate Scheme.booleanType.  Both are represented by a primitive boolean at run-time, but the latter handles Scheme "boolean-value" conversion.  The wrong type for eqv? causes the wrong return type for repeat? to inferred, which then lead to the faulty runtime cast.

Per Bothner <bothner>
Group administrator
Sat 21 Sep 2013 06:01:38 AM UTC, comment #1: 

Sorry, I thought I could guess next Savannah bug id but I was wrong :)

Attached an updated patch with the right savannah bug id.

Regards,
Matt

(file #29190)

Matthieu Vachon <maoueh>
Sat 21 Sep 2013 05:55:26 AM UTC, original submission:  

Consider the following snippet of code:


(let ((a 0) (b 0.01))
  (format #t "~a~%" (and (eqv? a 0) (not b))))


This will correctly print "#f" as we would expect. However, when this code is used within a function an return a result, the code results in a ClassCastException cannot convert DFloNum to Boolean.


(define (repeat? a b)
  (and (eqv? a 0) (not b)))

(format "~a~%" (repeat? 0 0.01))


The snippet above will fail with this exception:


java.lang.ClassCastException: gnu.math.DFloNum cannot be cast to java.lang.Boolean
        at atInteractiveLevel$2.isRepeat(boolean-double-cast-exception.scm:5)
        at atInteractiveLevel$2.apply2(boolean-double-cast-exception.scm:4)
        at gnu.expr.ModuleMethod.apply2(ModuleMethod.java:198)
        at atInteractiveLevel$3.run(boolean-double-cast-exception.scm:7)
...


I attached a patch that adds a failing testcase to Kawa about this bug.

Regards,
Matt

Matthieu Vachon <maoueh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #29190:  feature-sva40077-testcase.patch added by maoueh (2KiB - application/octet-stream)
file #29189:  feature-sva39949-testcase.patch added by maoueh (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by maoueh (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-09-24 bothner StatusNone Fixed
        Assigned toNone bothner
        Open/ClosedOpen Closed
    2013-09-21 maoueh Attached File- Added feature-sva40077-testcase.patch, #29190
    2013-09-21 maoueh Attached File- Added feature-sva39949-testcase.patch, #29189

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code