8013846: javac fails to reject semantically equivalent generic method declarations
authoremc
Thu, 12 Sep 2013 14:52:28 -0400
changeset 19938 a2ac24fff52e
parent 19937 7dacecdfbad4
child 19939 ab90fbc7b74e
8013846: javac fails to reject semantically equivalent generic method declarations Summary: Cause javac to consider intersection types with the same elements to be equal regardless of order. Reviewed-by: jjg, vromero
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/test/tools/javac/generics/neg/OrderedIntersections.java
langtools/test/tools/javac/generics/neg/OrderedIntersections.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Sep 11 14:50:11 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Sep 12 14:52:28 2013 -0400
@@ -3340,7 +3340,9 @@
                     (e.sym.flags() & CLASH) == 0 &&
                     sym.kind == e.sym.kind &&
                     sym.name != names.error &&
-                    (sym.kind != MTH || types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) {
+                    (sym.kind != MTH ||
+                     types.hasSameArgs(sym.type, e.sym.type) ||
+                     types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) {
                 if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) {
                     varargsDuplicateError(pos, sym, e.sym);
                     return true;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/neg/OrderedIntersections.java	Thu Sep 12 14:52:28 2013 -0400
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 6962494
+ * @summary The order of elements of intersection types shouldn't matter
+ * @compile/fail/ref=OrderedIntersections.out -XDrawDiagnostics OrderedIntersections.java
+ */
+
+interface i1 {}
+interface i2 {}
+
+public class OrderedIntersections {
+    static <t1 extends i1 & i2> Object smf(t1 x) {
+        System.out.println( " smf1 " );
+        return null;
+    }
+
+    static <t2 extends i2 & i1> Object smf(t2 x) {
+        System.out.println( " smf2 " );
+        return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/neg/OrderedIntersections.out	Thu Sep 12 14:52:28 2013 -0400
@@ -0,0 +1,2 @@
+OrderedIntersections.java:17:40: compiler.err.already.defined: kindname.method, <t1>smf(t1), kindname.class, OrderedIntersections
+1 error