diff --git a/src/share/classes/com/sun/tools/javac/comp/Check.java b/src/share/classes/com/sun/tools/javac/comp/Check.java index 342696ceed8b6fbb26e52efc03174ea6d8f3abcf..36188b6ff3e8ebe2d87755c10ca49bab30beccc9 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -1247,7 +1247,7 @@ public class Check { for (Type t2 = sup; t2.tag == CLASS; t2 = types.supertype(t2)) { - for (Scope.Entry e2 = t1.tsym.members().lookup(s1.name); + for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) { Symbol s2 = e2.sym; @@ -1394,6 +1394,16 @@ public class Check { 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()) { + Type er1 = m.erasure(types); + Type er2 = e.sym.erasure(types); + if (types.isSameType(er1,er2)) { + log.error(TreeInfo.diagnosticPositionFor(m, tree), + "name.clash.same.erasure.no.override", + m, m.location(), + e.sym, e.sym.location()); + } + } e = e.next(); } } diff --git a/test/tools/javac/generics/5009937/T5009937.java b/test/tools/javac/generics/5009937/T5009937.java new file mode 100644 index 0000000000000000000000000000000000000000..0e3d33297d06d82ef2f8918931e06e9ec3056435 --- /dev/null +++ b/test/tools/javac/generics/5009937/T5009937.java @@ -0,0 +1,41 @@ +/* + * Copyright 2008 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 5009937 + * @summary hiding versus generics versus binary compatibility + * @author Maurizio Cimadamore + * + * @compile/fail/ref=T5009937.out -XDstdout -XDrawDiagnostics T5009937.java + */ + +public class T5009937 { + static class A { + static void m(T5009937 l) {} + } + + static class B extends A { + static void m(T5009937 l) {} + } +} diff --git a/test/tools/javac/generics/5009937/T5009937.out b/test/tools/javac/generics/5009937/T5009937.out new file mode 100644 index 0000000000000000000000000000000000000000..0362b2dff96c4b80d7d6e04715e452c012e90ade --- /dev/null +++ b/test/tools/javac/generics/5009937/T5009937.out @@ -0,0 +1,2 @@ +T5009937.java:39:21: compiler.err.name.clash.same.erasure.no.override: m(T5009937), T5009937.B, m(T5009937), T5009937.A +1 error diff --git a/test/tools/javac/generics/InheritanceConflict.java b/test/tools/javac/generics/InheritanceConflict.java index df406b0b92706888cc92f94dbc26e84e500d0f8a..c66596130a6f022a6e5d32db33251398644f52c7 100644 --- a/test/tools/javac/generics/InheritanceConflict.java +++ b/test/tools/javac/generics/InheritanceConflict.java @@ -25,7 +25,7 @@ * @test * @bug 4984158 * @summary two inherited methods with same signature - * @author gafter + * @author gafter, Maurizio Cimadamore * * @compile/fail -source 1.5 InheritanceConflict.java */ @@ -34,8 +34,11 @@ package inheritance.conflict; class A { void f(String s) {} +} + +class B extends A { void f(T t) {} } -class B extends A { +class C extends B { } diff --git a/test/tools/javac/generics/InheritanceConflict2.java b/test/tools/javac/generics/InheritanceConflict2.java index fa234643a598a5922e2c2f12d9bc7c45b9c44693..2f6830d98edbf48bb17aafe3aa53e2514bf76329 100644 --- a/test/tools/javac/generics/InheritanceConflict2.java +++ b/test/tools/javac/generics/InheritanceConflict2.java @@ -25,7 +25,7 @@ * @test * @bug 4984158 * @summary two inherited methods with same signature - * @author gafter + * @author gafter, Maurizio Cimadamore * * @compile -source 1.5 InheritanceConflict2.java */ @@ -34,9 +34,12 @@ package inheritance.conflict2; class A { void f(String s) {} +} + +class B extends A { void f(T t) {} } -class B extends A { +class C extends B { void f(String s) {} }