Community
Participate
Working Groups
ajc emits an incorrect error that the return type is wrong when I use declare parents to declare that the return type implements the interface specified in the supertype method declaration. It does not appear to be true when using declare-parents on a class. The workaround is to declare the interface directly on the class. True in 1.5.0 and in HEAD today. /** * Declaring class works - see Bug below for declaring interface. */ public class CovariantDeclaredParent { interface Result {} public class Super { public Result result() {return null;} } class Sub extends Super { public C result() { return null; } } static aspect A { declare parents: C implements Result ; } class C {} } /** * Declaring interface on type should happen before any * covariant return types are evaluated. */ class Bug { interface Result {} interface Factory { Result getInstance(); } // uncomment to get more errors with default implementation // static aspect A { // // default implementation // public Result Factory.getInstance() { // throw new UnsupportedOperationException(); // } // } // D is factory for B static aspect A_forB { // bug: this should work declare parents: B implements Result; // Bug: get error here wrt invalid return type public B D.getInstance() { return new B(); } } static class D implements Factory {} static class B {} // to avoid the bug, declare interface directly on class // static class B implements Result {} }
yuck, an ordering problem. This program fails with 'ajc -1.5': interface Result {} interface Factory { Result getInstance(); } aspect A_forB { declare parents: B implements Result; public B D.getInstance() { return new B(); } } class D implements Factory {} class B {} ==== This program works, with B moved ahead of D: interface Result {} interface Factory { Result getInstance(); } aspect A_forB { declare parents: B implements Result; public B D.getInstance() { return new B(); } } class B {} class D implements Factory {}
testcase committed - commented out in ajc152tests