7020657: Javac rejects a fairly common idiom with raw override and interfaces

Wed, 23 Feb 2011 14:16:12 +0000

author
mcimadamore
date
Wed, 23 Feb 2011 14:16:12 +0000
changeset 889
015dc9a63efc
parent 884
75e25df50873
child 890
3ab7bb46c5c1

7020657: Javac rejects a fairly common idiom with raw override and interfaces
Summary: name clash should not be reported if subinterface/implementing class resolves the clash by defining common overrider
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7020657/T7020657neg.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7020657/T7020657neg.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/7020657/T7020657pos.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Feb 18 15:55:20 2011 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Feb 23 14:16:12 2011 +0000
     1.3 @@ -1679,7 +1679,8 @@
     1.4                              "(" + types.memberType(t2, s2).getParameterTypes() + ")");
     1.5                          return s2;
     1.6                      }
     1.7 -                } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2)) {
     1.8 +                } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) &&
     1.9 +                        !checkCommonOverriderIn(s1, s2, site)) {
    1.10                      log.error(pos,
    1.11                              "name.clash.same.erasure.no.override",
    1.12                              s1, s1.location(),
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/7020657/T7020657neg.java	Wed Feb 23 14:16:12 2011 +0000
     2.3 @@ -0,0 +1,23 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug 7020657 6985719
     2.7 + *
     2.8 + * @summary  Javac rejects a fairly common idiom with raw override and interfaces
     2.9 + * @author Maurizio Cimadamore
    2.10 + * @compile/fail/ref=T7020657neg.out -XDrawDiagnostics T7020657neg.java
    2.11 + *
    2.12 + */
    2.13 +
    2.14 +import java.util.*;
    2.15 +
    2.16 +class T7020657neg {
    2.17 +    interface A {
    2.18 +        int get(List<String> l);
    2.19 +    }
    2.20 +
    2.21 +    interface B  {
    2.22 +        int get(List<Integer> l);
    2.23 +    }
    2.24 +
    2.25 +    interface C extends A, B { }
    2.26 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/7020657/T7020657neg.out	Wed Feb 23 14:16:12 2011 +0000
     3.3 @@ -0,0 +1,2 @@
     3.4 +T7020657neg.java:22:5: compiler.err.name.clash.same.erasure.no.override: get(java.util.List<java.lang.Integer>), T7020657neg.B, get(java.util.List<java.lang.String>), T7020657neg.A
     3.5 +1 error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/7020657/T7020657pos.java	Wed Feb 23 14:16:12 2011 +0000
     4.3 @@ -0,0 +1,48 @@
     4.4 +/*
     4.5 + * Copyright (c) 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +
    4.27 +/*
    4.28 + * @test
    4.29 + * @bug 7020657 6985719
    4.30 + *
    4.31 + * @summary  Javac rejects a fairly common idiom with raw override and interfaces
    4.32 + * @author Robert Field
    4.33 + * @compile T7020657pos.java
    4.34 + *
    4.35 + */
    4.36 +
    4.37 +import java.util.*;
    4.38 +
    4.39 +class T7020657pos {
    4.40 +    interface A {
    4.41 +        int get(List<String> l);
    4.42 +    }
    4.43 +
    4.44 +    interface B  {
    4.45 +        int get(List<Integer> l);
    4.46 +    }
    4.47 +
    4.48 +    interface C extends A, B {
    4.49 +        int get(List l);
    4.50 +    }
    4.51 +}

mercurial