aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormcimadamore <none@none>2011-04-12 20:58:06 -0700
committermcimadamore <none@none>2011-04-12 20:58:06 -0700
commita033f58d2c3d71329a2e2c4dbf4a6fe36b4538bd (patch)
treee473c267fbb84c94a6b4a06b5da160cbc620b29a
parent0f687cdd3ae597526fe51795e9186d5735bce9ba (diff)
7034019: ClassCastException in javac with conjunction types
Summary: Resolve.mostSpecific doesn't handle case of raw override Reviewed-by: dlsmith
-rw-r--r--src/share/classes/com/sun/tools/javac/comp/Resolve.java7
-rw-r--r--test/tools/javac/generics/7034019/T7034019a.java46
-rw-r--r--test/tools/javac/generics/7034019/T7034019b.java46
-rw-r--r--test/tools/javac/generics/7034019/T7034019c.java23
-rw-r--r--test/tools/javac/generics/7034019/T7034019c.out3
-rw-r--r--test/tools/javac/generics/7034019/T7034019d.java23
-rw-r--r--test/tools/javac/generics/7034019/T7034019d.out3
7 files changed, 146 insertions, 5 deletions
diff --git a/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/share/classes/com/sun/tools/javac/comp/Resolve.java
index 301a3aeb..94ddd16f 100644
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -770,12 +770,9 @@ public class Resolve {
return ambiguityError(m1, m2);
// both abstract, neither overridden; merge throws clause and result type
Symbol mostSpecific;
- Type result2 = mt2.getReturnType();
- if (mt2.tag == FORALL)
- result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
- if (types.isSubtype(mt1.getReturnType(), result2))
+ if (types.returnTypeSubstitutable(mt1, mt2))
mostSpecific = m1;
- else if (types.isSubtype(result2, mt1.getReturnType()))
+ else if (types.returnTypeSubstitutable(mt2, mt1))
mostSpecific = m2;
else {
// Theoretically, this can't happen, but it is possible
diff --git a/test/tools/javac/generics/7034019/T7034019a.java b/test/tools/javac/generics/7034019/T7034019a.java
new file mode 100644
index 00000000..f1c5bb57
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019a.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile T7034019a.java
+ */
+
+class T7034019a {
+ interface A {
+ abstract <T> void foo();
+ }
+
+ interface B {
+ abstract void foo();
+ }
+
+ static class C<T extends A & B> {
+ void test(T x) {
+ x.foo();
+ }
+ }
+}
diff --git a/test/tools/javac/generics/7034019/T7034019b.java b/test/tools/javac/generics/7034019/T7034019b.java
new file mode 100644
index 00000000..5d3d1400
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019b.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile T7034019b.java
+ */
+
+class T7034019a {
+ interface A {
+ <T> void foo();
+ }
+
+ interface B {
+ void foo();
+ }
+
+ static abstract class E implements A,B {
+ void test() {
+ foo();
+ }
+ }
+}
diff --git a/test/tools/javac/generics/7034019/T7034019c.java b/test/tools/javac/generics/7034019/T7034019c.java
new file mode 100644
index 00000000..c9fc6a16
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019c.java
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile/fail/ref=T7034019c.out -XDrawDiagnostics T7034019c.java
+ */
+
+class T7034019c {
+ interface A {
+ abstract <T extends Number> T foo();
+ }
+
+ interface B {
+ abstract <T> T foo();
+ }
+
+ static class C<T extends A & B> {
+ void test(T x) {
+ x.foo();
+ }
+ }
+}
diff --git a/test/tools/javac/generics/7034019/T7034019c.out b/test/tools/javac/generics/7034019/T7034019c.out
new file mode 100644
index 00000000..55845589
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019c.out
@@ -0,0 +1,3 @@
+T7034019c.java:18:20: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
+T7034019c.java:20:14: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
+2 errors
diff --git a/test/tools/javac/generics/7034019/T7034019d.java b/test/tools/javac/generics/7034019/T7034019d.java
new file mode 100644
index 00000000..63a16543
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019d.java
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile/fail/ref=T7034019d.out -XDrawDiagnostics T7034019d.java
+ */
+
+class T7034019c {
+ interface A {
+ abstract <T extends Number> T foo();
+ }
+
+ interface B {
+ abstract <T> T foo();
+ }
+
+ static abstract class E implements A,B {
+ void test() {
+ foo();
+ }
+ }
+}
diff --git a/test/tools/javac/generics/7034019/T7034019d.out b/test/tools/javac/generics/7034019/T7034019d.out
new file mode 100644
index 00000000..bfd6fa0b
--- /dev/null
+++ b/test/tools/javac/generics/7034019/T7034019d.out
@@ -0,0 +1,3 @@
+T7034019d.java:18:21: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
+T7034019d.java:20:13: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
+2 errors