summaryrefslogtreecommitdiffstats
path: root/tests/bugs152/pr128443/CovariantDeclaredParent.java
blob: fad498960377e91df4c4a81c92dd67565d792513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * 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 {}

}