Bug 128443 - declare-parents ineffective for return interface of overridden method
Summary: declare-parents ineffective for return interface of overridden method
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-17 12:36 EST by Wes Isberg CLA
Modified: 2007-10-23 12:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wes Isberg CLA 2006-02-17 12:36:07 EST
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 {}

}
Comment 1 Andrew Clement CLA 2006-05-18 10:39:16 EDT
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 {}


Comment 2 Andrew Clement CLA 2006-05-22 06:24:54 EDT
testcase committed - commented out in ajc152tests