History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-1183
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Charles Oliver Nutter
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JRuby

New closure conversion should prefer methods with convertable args over those without

Created: 03/Jul/07 01:28 AM   Updated: 08/Aug/08 01:10 AM
Component/s: Java Integration
Affects Version/s: JRuby 1.1b1
Fix Version/s: JRuby 1.1.4

Time Tracking:
Not Specified


 Description  « Hide
We should be able to do java.lang.Thread.new { puts 'hello' } and expect to get back a thread object with the given proc as its Runnable. However it appears that the conversion of the proc to runnable gets superceded by the no-arg version of the Thread constructor, and so the converted proc is never used.

It seems that when passing a block to a Java method, we should first try to find methods for which a converted closure would work, and then fall back on versions without convertible interfaces.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Nick Sieger - 03/Jul/07 08:49 AM
I think that normally the logic will work as you describe. Blocks will always get converted into args and passed to java methods. What you found here is actually a missing feature that I didn't get the conversion working with constructors.

Charles Oliver Nutter - 03/Jul/07 11:17 PM
But this works:
jruby -e "include Java; java.lang.Thread.new(proc {puts 'hello'}).start"
=> hello

It still seems like it's an issue of not considering an incoming block as an argument for method lookup purposes, at least in this case.


Nick Sieger - 03/Jul/07 11:40 PM
Yeah, I saw this myself as I was writing the code. Plain and simple, a block won't be treated as an argument to a constructor. The code path for blocks-as-args-to-constructors was a little bit more ugly to get working than with method invocations.

Charles Oliver Nutter - 21/Oct/07 11:37 PM
Nick, is it possible to get closure coercion on constructors working for 1.1?

Charles Oliver Nutter - 15/Feb/08 12:58 PM
Punting issues from 1.1 RC2 to 1.1 final.

Charles Oliver Nutter - 08/Aug/08 01:10 AM
Fixed with tests. Closure conversion now works for constructors and static methods as well as instance methods.