6182950: methods clash algorithm should not depend on return type
authormcimadamore
Wed, 25 Mar 2009 10:28:36 +0000
changeset 2509 c8a1744c87fd
parent 2322 5250b269afaa
child 2510 d7ba8e16a928
6182950: methods clash algorithm should not depend on return type Summary: fixed code that checks for duplicate method declarations Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/test/tools/javac/generics/6182950/T6182950a.java
langtools/test/tools/javac/generics/6182950/T6182950a.out
langtools/test/tools/javac/generics/6182950/T6182950b.java
langtools/test/tools/javac/generics/6182950/T6182950b.out
langtools/test/tools/javac/generics/6182950/T6182950c.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Sat Mar 21 13:53:11 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Mar 25 10:28:36 2009 +0000
@@ -1458,10 +1458,14 @@
             while (e.scope != null) {
                 if (m.overrides(e.sym, origin, types, false))
                     checkOverride(tree, m, (MethodSymbol)e.sym, origin);
-                else if (e.sym.isInheritedIn(origin, types) && !m.isConstructor()) {
+                else if (e.sym.kind == MTH &&
+                        e.sym.isInheritedIn(origin, types) &&
+                        (e.sym.flags() & SYNTHETIC) == 0 &&
+                        !m.isConstructor()) {
                     Type er1 = m.erasure(types);
                     Type er2 = e.sym.erasure(types);
-                    if (types.isSameType(er1,er2)) {
+                    if (types.isSameTypes(er1.getParameterTypes(),
+                            er2.getParameterTypes())) {
                             log.error(TreeInfo.diagnosticPositionFor(m, tree),
                                     "name.clash.same.erasure.no.override",
                                     m, m.location(),
@@ -2088,9 +2092,11 @@
             if (sym != e.sym &&
                 sym.kind == e.sym.kind &&
                 sym.name != names.error &&
-                (sym.kind != MTH || types.overrideEquivalent(sym.type, e.sym.type))) {
+                (sym.kind != MTH || types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) {
                 if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS))
                     varargsDuplicateError(pos, sym, e.sym);
+                else if (sym.kind == MTH && !types.overrideEquivalent(sym.type, e.sym.type))
+                    duplicateErasureError(pos, sym, e.sym);
                 else
                     duplicateError(pos, e.sym);
                 return false;
@@ -2098,6 +2104,14 @@
         }
         return true;
     }
+    //where
+    /** Report duplicate declaration error.
+     */
+    void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
+        if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
+            log.error(pos, "name.clash.same.erasure", sym1, sym2);
+        }
+    }
 
     /** Check that single-type import is not already imported or top-level defined,
      *  but make an exception for two single-type imports which denote the same type.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/6182950/T6182950a.java	Wed Mar 25 10:28:36 2009 +0000
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6182950
+ * @summary methods clash algorithm should not depend on return type
+ * @author  mcimadamore
+ * @compile/fail/ref=T6182950a.out -XDrawDiagnostics T6182950a.java
+ */
+import java.util.List;
+
+class T6182950a {
+    int m(List<String> l) {return 0;}
+    double m(List<Integer> l) {return 0;}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/6182950/T6182950a.out	Wed Mar 25 10:28:36 2009 +0000
@@ -0,0 +1,2 @@
+T6182950a.java:35:12: compiler.err.name.clash.same.erasure: m(java.util.List<java.lang.Integer>), m(java.util.List<java.lang.String>)
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/6182950/T6182950b.java	Wed Mar 25 10:28:36 2009 +0000
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6182950
+ * @summary methods clash algorithm should not depend on return type
+ * @author  mcimadamore
+ * @compile/fail/ref=T6182950b.out -XDrawDiagnostics T6182950b.java
+ */
+import java.util.List;
+
+class T6182950b {
+    static class A {
+        int m(List<String> l) {return 0;}
+    }
+    static class B extends A {
+        double m(List<Integer> l) {return 0;}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/6182950/T6182950b.out	Wed Mar 25 10:28:36 2009 +0000
@@ -0,0 +1,2 @@
+T6182950b.java:38:16: compiler.err.name.clash.same.erasure.no.override: m(java.util.List<java.lang.Integer>), T6182950b.B, m(java.util.List<java.lang.String>), T6182950b.A
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/6182950/T6182950c.java	Wed Mar 25 10:28:36 2009 +0000
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug     6182950
+ * @summary methods clash algorithm should not depend on return type
+ * @author  mcimadamore
+ * @compile T6182950c.java
+ */
+
+class T6182950c {
+    static abstract class A<X> {
+        abstract Object m(X x);
+    }
+
+    static abstract class B<X> extends A<X> {
+        Number m(X x) {return 0;}
+    }
+
+    final static class C<X> extends B<X> {
+        Integer m(X x) {return 0;}
+    }
+}