[Jastadd] [bug report] overloaded methods in an inner class of a generic class

From: Na, Hyunik <hina_at_kaist.ac.kr>
Date: Sun, 18 Mar 2012 17:38:00 +0900

Hello JastAddJ deverlopers,

 

For the following example,

 

-=-=-=

public class Test {

  public static void main( String [] args ) {

    C<F> c = new C<F>();

    c.new D( new F() );

  }

}

 

class C<X> {

  class D {

    D( X e ) { }

    D( F e ) { }

  }

}

 

class F { }

-=-=-=

 

javac produces the following error message.

 

-=-=-=

[hina_at_hyunikLinux test]$ javac Test.java

Test.java:8: reference to D is ambiguous, both method D(X) in C<F>.D and
method D(F) in C<F>.D match

    c.new D( new F() );

      ^

1 error

-=-=-=

 

But, JastAddJ (rev. 9233) allows this program.

 

Though I have not examined the Java language specification about this issue,
javac's result seems more reasonable.

 

To get a similar result as javac, the following simple modification of
ConstructorDecl.moreSpecificThan(ConstructorDecl) may be adequate

 

-=-=-=

syn lazy boolean ConstructorDecl.moreSpecificThan(ConstructorDecl m) {

    boolean diffFound = false; // *

   for(int i = 0; i < getNumParameter(); i++) {

      if(!getParameter(i).type().instanceOf(m.getParameter(i).type()))

        return false;

 
if(!getParameter(i).type().identityConversionTo(m.getParameter(i).type()))
// *

        diffFound = true; // *

    }

    if ( !diffFound ) return false; // *

    return true;

}

-=-=-=

 

where added four lines are marked by "// *".

 

Current ConstructorDecl.moreSpecificThan() returns true not only for a "more
specific" case, but also for a "equally specific" case.

The above modification is to return false for equally specific cases.

Similar things should be done to MothodDecl.moreSpecificThan() and to the
refined moreSpecificThan()'s for variable arity

constructors and methods in Java1.5Frontend/MethodSignature.jrag.

 

I hope this helps.

 

Cheers,

- Hyunik
Received on Sun Mar 18 2012 - 09:39:48 CET

This archive was generated by hypermail 2.3.0 : Wed Apr 16 2014 - 17:19:06 CEST