aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/bugs152/pr128443/Bug.java23
-rw-r--r--tests/bugs152/pr128443/Covariance.java16
-rw-r--r--tests/bugs152/pr128443/CovariantDeclaredParent.java54
3 files changed, 93 insertions, 0 deletions
diff --git a/tests/bugs152/pr128443/Bug.java b/tests/bugs152/pr128443/Bug.java
new file mode 100644
index 000000000..afc95c46f
--- /dev/null
+++ b/tests/bugs152/pr128443/Bug.java
@@ -0,0 +1,23 @@
+
+
+interface Result {}
+
+interface Factory {
+ Result getInstance();
+}
+
+class B {}
+
+class D implements Factory {}
+
+aspect EnsureBImplementsResult {
+
+ // bug: this should work
+ declare parents: B implements Result;
+
+
+ // bug: get error here wrt invalid return type
+ public B D.getInstance() {
+ return new B();
+ }
+}
diff --git a/tests/bugs152/pr128443/Covariance.java b/tests/bugs152/pr128443/Covariance.java
new file mode 100644
index 000000000..2263c6700
--- /dev/null
+++ b/tests/bugs152/pr128443/Covariance.java
@@ -0,0 +1,16 @@
+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 {}
diff --git a/tests/bugs152/pr128443/CovariantDeclaredParent.java b/tests/bugs152/pr128443/CovariantDeclaredParent.java
new file mode 100644
index 000000000..fad498960
--- /dev/null
+++ b/tests/bugs152/pr128443/CovariantDeclaredParent.java
@@ -0,0 +1,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 {}
+
+}