bugKawa - Bugs: bug #48938, lambda cannot be cast to...

 
 

bug #48938: lambda cannot be cast to java.util.Comparator

Submitted by:  Sakamoto Osamu <saka1029>
Submitted on:  Mon 29 Aug 2016 02:48:59 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Per Bothner <bothner>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 30 Aug 2016 04:45:05 AM UTC, comment #2:

I checked in fix, along with your testcase. Thanks!

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Mon 29 Aug 2016 05:20:28 AM UTC, comment #1:

I'm guessing this is because Comparator has an equals method, which Kawa doesn't realize has a default implementation (in Object).

Should be relatively easy to fix.

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Mon 29 Aug 2016 02:48:59 AM UTC, original submission:

I defined a macro.

(define-syntax ->
(syntax-rules ()
((_ o)
o)
((_ o (m a ...) r ...)
(-> (invoke o 'm a ...) r ...))
((_ o f r ...)
(-> (field o 'f) r ...))))

And I called java8 stream APIs.

#|kawa:68|# (-> [1 3 5 7 9 8 6 4 2]
#|(---:69|# (stream)
#|(---:70|# (filter (lambda (x) (<= x 5)))
#|(---:71|# (sorted)
#|(---:72|# (toArray))
[1 2 3 4 5]

It works fine.
But when I add an argument to 'sorted' method, it doesn't work.

#|kawa:73|# (-> [1 3 5 7 9 8 6 4 2]
#|(---:74|# (stream)
#|(---:75|# (filter (lambda (x) (<= x 5)))
#|(---:76|# (sorted (lambda (a b) (- b a)))
#|(---:77|# (toArray))
/dev/stdin:76:13: warning - type function is incompatible with required type java.util.Comparator
java.lang.ClassCastException: gnu.expr.ModuleMethod cannot be cast to java.util.Comparator
at atInteractiveLevel-21.run(stdin:75)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
at kawa.Shell.run(Shell.java:291)
at kawa.Shell.run(Shell.java:203)
at kawa.Shell.run(Shell.java:184)
at kawa.repl.processArgs(repl.java:687)
at kawa.repl.main(repl.java:793)

Sakamoto Osamu <saka1029>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 16 Jan 2017 05:04:25 PM UTCbothnerOpen/ClosedOpen=>Closed
    Tue 30 Aug 2016 04:45:05 AM UTCbothnerStatusIn Progress=>Fixed
    Mon 29 Aug 2016 05:20:28 AM UTCbothnerStatusNone=>In Progress
      Assigned toNone=>bothner
    Mon 29 Aug 2016 02:48:59 AM UTCsaka1029Carbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1