6182950: methods clash algorithm should not depend on return type

Wed, 25 Mar 2009 10:28:36 +0000

author
mcimadamore
date
Wed, 25 Mar 2009 10:28:36 +0000
changeset 252
5caa6c45936a
parent 245
3bf905cb80e7
child 253
6ce39250fa88

6182950: methods clash algorithm should not depend on return type
Summary: fixed code that checks for duplicate method declarations
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6182950/T6182950a.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6182950/T6182950a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6182950/T6182950b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6182950/T6182950b.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6182950/T6182950c.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Sat Mar 21 13:53:11 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Mar 25 10:28:36 2009 +0000
     1.3 @@ -1458,10 +1458,14 @@
     1.4              while (e.scope != null) {
     1.5                  if (m.overrides(e.sym, origin, types, false))
     1.6                      checkOverride(tree, m, (MethodSymbol)e.sym, origin);
     1.7 -                else if (e.sym.isInheritedIn(origin, types) && !m.isConstructor()) {
     1.8 +                else if (e.sym.kind == MTH &&
     1.9 +                        e.sym.isInheritedIn(origin, types) &&
    1.10 +                        (e.sym.flags() & SYNTHETIC) == 0 &&
    1.11 +                        !m.isConstructor()) {
    1.12                      Type er1 = m.erasure(types);
    1.13                      Type er2 = e.sym.erasure(types);
    1.14 -                    if (types.isSameType(er1,er2)) {
    1.15 +                    if (types.isSameTypes(er1.getParameterTypes(),
    1.16 +                            er2.getParameterTypes())) {
    1.17                              log.error(TreeInfo.diagnosticPositionFor(m, tree),
    1.18                                      "name.clash.same.erasure.no.override",
    1.19                                      m, m.location(),
    1.20 @@ -2088,9 +2092,11 @@
    1.21              if (sym != e.sym &&
    1.22                  sym.kind == e.sym.kind &&
    1.23                  sym.name != names.error &&
    1.24 -                (sym.kind != MTH || types.overrideEquivalent(sym.type, e.sym.type))) {
    1.25 +                (sym.kind != MTH || types.hasSameArgs(types.erasure(sym.type), types.erasure(e.sym.type)))) {
    1.26                  if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS))
    1.27                      varargsDuplicateError(pos, sym, e.sym);
    1.28 +                else if (sym.kind == MTH && !types.overrideEquivalent(sym.type, e.sym.type))
    1.29 +                    duplicateErasureError(pos, sym, e.sym);
    1.30                  else
    1.31                      duplicateError(pos, e.sym);
    1.32                  return false;
    1.33 @@ -2098,6 +2104,14 @@
    1.34          }
    1.35          return true;
    1.36      }
    1.37 +    //where
    1.38 +    /** Report duplicate declaration error.
    1.39 +     */
    1.40 +    void duplicateErasureError(DiagnosticPosition pos, Symbol sym1, Symbol sym2) {
    1.41 +        if (!sym1.type.isErroneous() && !sym2.type.isErroneous()) {
    1.42 +            log.error(pos, "name.clash.same.erasure", sym1, sym2);
    1.43 +        }
    1.44 +    }
    1.45  
    1.46      /** Check that single-type import is not already imported or top-level defined,
    1.47       *  but make an exception for two single-type imports which denote the same type.
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/6182950/T6182950a.java	Wed Mar 25 10:28:36 2009 +0000
     2.3 @@ -0,0 +1,36 @@
     2.4 +/*
     2.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug     6182950
    2.30 + * @summary methods clash algorithm should not depend on return type
    2.31 + * @author  mcimadamore
    2.32 + * @compile/fail/ref=T6182950a.out -XDrawDiagnostics T6182950a.java
    2.33 + */
    2.34 +import java.util.List;
    2.35 +
    2.36 +class T6182950a {
    2.37 +    int m(List<String> l) {return 0;}
    2.38 +    double m(List<Integer> l) {return 0;}
    2.39 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/6182950/T6182950a.out	Wed Mar 25 10:28:36 2009 +0000
     3.3 @@ -0,0 +1,2 @@
     3.4 +T6182950a.java:35:12: compiler.err.name.clash.same.erasure: m(java.util.List<java.lang.Integer>), m(java.util.List<java.lang.String>)
     3.5 +1 error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/6182950/T6182950b.java	Wed Mar 25 10:28:36 2009 +0000
     4.3 @@ -0,0 +1,40 @@
     4.4 +/*
     4.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    4.24 + * have any questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug     6182950
    4.30 + * @summary methods clash algorithm should not depend on return type
    4.31 + * @author  mcimadamore
    4.32 + * @compile/fail/ref=T6182950b.out -XDrawDiagnostics T6182950b.java
    4.33 + */
    4.34 +import java.util.List;
    4.35 +
    4.36 +class T6182950b {
    4.37 +    static class A {
    4.38 +        int m(List<String> l) {return 0;}
    4.39 +    }
    4.40 +    static class B extends A {
    4.41 +        double m(List<Integer> l) {return 0;}
    4.42 +    }
    4.43 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/6182950/T6182950b.out	Wed Mar 25 10:28:36 2009 +0000
     5.3 @@ -0,0 +1,2 @@
     5.4 +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
     5.5 +1 error
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/6182950/T6182950c.java	Wed Mar 25 10:28:36 2009 +0000
     6.3 @@ -0,0 +1,44 @@
     6.4 +/*
     6.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.24 + * have any questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug     6182950
    6.30 + * @summary methods clash algorithm should not depend on return type
    6.31 + * @author  mcimadamore
    6.32 + * @compile T6182950c.java
    6.33 + */
    6.34 +
    6.35 +class T6182950c {
    6.36 +    static abstract class A<X> {
    6.37 +        abstract Object m(X x);
    6.38 +    }
    6.39 +
    6.40 +    static abstract class B<X> extends A<X> {
    6.41 +        Number m(X x) {return 0;}
    6.42 +    }
    6.43 +
    6.44 +    final static class C<X> extends B<X> {
    6.45 +        Integer m(X x) {return 0;}
    6.46 +    }
    6.47 +}

mercurial