Bug 91381 - Abstract intertype methods and covariant returns
Summary: Abstract intertype methods and covariant returns
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M2   Edit
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-14 05:45 EDT by Aske Simon Christensen CLA
Modified: 2005-08-25 03:21 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aske Simon Christensen CLA 2005-04-14 05:45:17 EDT
The following program is accepted by ajc -1.5:


public aspect AbstractITD {
    public abstract Object A.foo();

    public static void main(String[] args) {
	A a = new B();
	System.out.println(a.foo());
    }
}

abstract class A {}

class B extends A {
    public Integer foo() { return new Integer(42); }
}

But it does not put in the necessary bridge method, so the program throws an
AbstractMethodError at runtime:

Exception in thread "main" java.lang.AbstractMethodError: A.foo()Ljava/lang/Object;
        at AbstractITD.ajc$interMethodDispatch1$AbstractITD$A$foo(AbstractITD.java)
        at AbstractITD.main(AbstractITD.java:7)

ajc without -1.5 does not reject the program. I guess it should, since covariant
return type is a 1.5 feature.

Also, if the @Override annotation is put on the method in B, ajc -1.5 complains,
even though the method does override a superclass method.
Comment 1 Adrian Colyer CLA 2005-08-19 14:51:42 EDT
Raising priority for compiler course starting 28/8. Will give it a shot - itds and generics are the one area 
we're held up on for M3 at the moment, proving quite tricky to get everything nailed....
Comment 2 Andrew Clement CLA 2005-08-23 17:42:57 EDT
@Override problem is now fixed.

And just collecting notes in this bug...Some ITD variants work and the bridge
methods are created, for example:

public class Super2 {
  public Object m() { return null;}
}
public class Sub2 extends Super2 { }
public aspect X2 {
  public Integer Sub2.m() {return new Integer(42);}
}

produces a version of Sub2 that looks like this:

public class Sub2 extends Super2{
    public Sub2();
    public java.lang.Object m();
    public java.lang.Integer m();
}

we get that free from the JDT compiler as it knows ITDs are around.  I'm not
sure why it has trouble if the ITD is on the supertype.  and we'll also need to
take binary weaving/separate compilation into account - so we can't always rely
on the JDT compiler to generate the necessary methods :(
Comment 3 Andrew Clement CLA 2005-08-24 11:41:09 EDT
I've fixed this.  We now generate the bridge methods you would expect.  I
haven't explored the space with testcases tho - so I wouldn't be surprised if
there are other problems lurking.

The dev build will appear in a little while - in the meantime, you can try this
special build I've just created for another user that happens to also contain
this fix:

http://download.eclipse.org/technology/aspectj/dev/aspectj-PR107784.jar

What I haven't fixed/checked is the policing of using covariant features when
not using 1.5 mode - will look at that now.
Comment 4 Andrew Clement CLA 2005-08-24 12:45:31 EDT
Ok, I checked the final problem and you do get an error.  This program

public aspect pr91381_2 {
  public abstract Object A.foo();

  public static void main(String[] args) {
    A a = new B();
    System.out.println(a.foo());
  }
}

abstract class A {

}

class B extends A {
  public Integer foo() { return new Integer(42); }
}

reports: 

[error 1] error at public Integer foo() { return new Integer(42); }
               ^^
C:\temp\ajcSandbox\ajcTest25015.tmp\pr91381_2.aj:15:0::0 The return type is
incompatible with A.foo()

will close the bug when the build is available.
Comment 5 Andrew Clement CLA 2005-08-25 03:21:20 EDT
build available - all 3 issues reported have been fixed.