Overloaded Java method selection doesn't see all possible coercions
-------------------------------------------------------------------

                 Key: JRUBY-5476
                 URL: http://jira.codehaus.org/browse/JRUBY-5476
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
    Affects Versions: JRuby 1.6RC2
            Reporter: Charles Oliver Nutter


The case I ran into was from "madmarco" on IRC. In his case, he was trying to 
reify a Ruby class and pass it to a method that accepts a java.lang.Class.

It works for a simple case:

{noformat}
~/projects/jruby ➔ mirahc -e "def foo(c:Class); puts 
c.getMethods.length; end"

~/projects/jruby ➔ jruby -rjruby/core_ext -rjava -e 'class Foo; end; 
Foo.become_java!; Java::DashE.foo(Foo)'
203

~/projects/jruby ➔ javap DashE
Compiled from DashE
public class DashE extends java.lang.Object{
    public static void main(java.lang.String[]);
    public static java.io.PrintStream foo(java.lang.Class);
    public DashE();
}
{noformat}

But fails when there's overloads of the method/constructor in question:

{noformat}
~/projects/jruby ➔ mirahc -e "def foo(c:Class); puts 
c.getMethods.length; end; def foo(a:String, c:Class); end"

~/projects/jruby ➔ javap DashE
Compiled from DashE
public class DashE extends java.lang.Object{
    public static void main(java.lang.String[]);
    public static java.io.PrintStream foo(java.lang.Class);
    public static java.lang.Object foo(java.lang.String, java.lang.Class);
    public DashE();
}


~/projects/jruby ➔ jruby -rjruby/core_ext -rjava -e 'class Foo; end; 
Foo.become_java!; Java::DashE.foo(Foo)'
-e:1:in `(root)': no foo with arguments matching [class org.jruby.RubyClass] on 
object Java::Default::DashE (NameError)
{noformat}

The problem here is that our overload selection does not know about what toJava 
supports on various classes. So in this case, it doesn't know that toJava 
*would* return an appropriate java.lang.Class object, and so it refuses to 
select that overload.

The workaround for now is to explicitly coerce the object to the appropriate 
type, such as using to_java. In this case, calling the method with 
Foo.to_java(:class) works correctly.

The fix is that we need overload selection to know about each argument's 
supported types.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to