提交 c26ae9ea 编写于 作者: M mcimadamore

6182950: methods clash algorithm should not depend on return type

Summary: fixed code that checks for duplicate method declarations
Reviewed-by: jjg
上级 2e4f40f8
......@@ -1458,10 +1458,14 @@ 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()) {
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 @@ public class Check {
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 @@ public class Check {
}
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.
......
/*
* 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;}
}
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
/*
* 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;}
}
}
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
/*
* 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;}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册