6294779: Problem with interface inheritance and covariant return types
Problematic overriding check when two methods defined in two distinct superinterfaces are overriden by an interface Reviewed-by: jjg
This commit is contained in:
parent
cfd8c6e652
commit
f33c28c7fb
langtools
src/share/classes/com/sun/tools/javac/comp
test/tools/javac/generics/6294779
@ -1367,13 +1367,47 @@ public class Check {
|
||||
types.isSameType(rt1, rt2) ||
|
||||
rt1.tag >= CLASS && rt2.tag >= CLASS &&
|
||||
(types.covariantReturnType(rt1, rt2, Warner.noWarnings) ||
|
||||
types.covariantReturnType(rt2, rt1, Warner.noWarnings));
|
||||
types.covariantReturnType(rt2, rt1, Warner.noWarnings)) ||
|
||||
checkCommonOverriderIn(s1,s2,site);
|
||||
if (!compat) return s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//WHERE
|
||||
boolean checkCommonOverriderIn(Symbol s1, Symbol s2, Type site) {
|
||||
Map<TypeSymbol,Type> supertypes = new HashMap<TypeSymbol,Type>();
|
||||
Type st1 = types.memberType(site, s1);
|
||||
Type st2 = types.memberType(site, s2);
|
||||
closure(site, supertypes);
|
||||
for (Type t : supertypes.values()) {
|
||||
for (Scope.Entry e = t.tsym.members().lookup(s1.name); e.scope != null; e = e.next()) {
|
||||
Symbol s3 = e.sym;
|
||||
if (s3 == s1 || s3 == s2 || s3.kind != MTH || (s3.flags() & (BRIDGE|SYNTHETIC)) != 0) continue;
|
||||
Type st3 = types.memberType(site,s3);
|
||||
if (types.overrideEquivalent(st3, st1) && types.overrideEquivalent(st3, st2)) {
|
||||
if (s3.owner == site.tsym) {
|
||||
return true;
|
||||
}
|
||||
List<Type> tvars1 = st1.getTypeArguments();
|
||||
List<Type> tvars2 = st2.getTypeArguments();
|
||||
List<Type> tvars3 = st3.getTypeArguments();
|
||||
Type rt1 = st1.getReturnType();
|
||||
Type rt2 = st2.getReturnType();
|
||||
Type rt13 = types.subst(st3.getReturnType(), tvars3, tvars1);
|
||||
Type rt23 = types.subst(st3.getReturnType(), tvars3, tvars2);
|
||||
boolean compat =
|
||||
rt13.tag >= CLASS && rt23.tag >= CLASS &&
|
||||
(types.covariantReturnType(rt13, rt1, Warner.noWarnings) &&
|
||||
types.covariantReturnType(rt23, rt2, Warner.noWarnings));
|
||||
if (compat)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Check that a given method conforms with any method it overrides.
|
||||
* @param tree The tree from which positions are extracted
|
||||
|
49
langtools/test/tools/javac/generics/6294779/T6294779a.java
Normal file
49
langtools/test/tools/javac/generics/6294779/T6294779a.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 6294779
|
||||
* @summary Problem with interface inheritance and covariant return types
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile T6294779a.java
|
||||
*/
|
||||
|
||||
public class T6294779a {
|
||||
|
||||
interface A {
|
||||
A m();
|
||||
}
|
||||
|
||||
interface B extends A {
|
||||
B m();
|
||||
}
|
||||
|
||||
interface C extends A {
|
||||
C m();
|
||||
}
|
||||
|
||||
interface D extends B, C {
|
||||
D m();
|
||||
}
|
||||
}
|
49
langtools/test/tools/javac/generics/6294779/T6294779b.java
Normal file
49
langtools/test/tools/javac/generics/6294779/T6294779b.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 6294779
|
||||
* @summary Problem with interface inheritance and covariant return types
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile T6294779b.java
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class T6294779b {
|
||||
|
||||
interface I1<E> {
|
||||
List<E> m();
|
||||
}
|
||||
|
||||
interface I2<E> {
|
||||
Queue<E> m();
|
||||
}
|
||||
|
||||
interface I3<E> {
|
||||
LinkedList<E> m();
|
||||
}
|
||||
|
||||
interface I4<E> extends I1<E>, I2<E>, I3<E> {}
|
||||
}
|
53
langtools/test/tools/javac/generics/6294779/T6294779c.java
Normal file
53
langtools/test/tools/javac/generics/6294779/T6294779c.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 6294779
|
||||
* @summary Problem with interface inheritance and covariant return types
|
||||
* @author Maurizio Cimadamore
|
||||
* @compile/fail T6294779c.java
|
||||
*/
|
||||
|
||||
public class T6294779c<X> {
|
||||
|
||||
interface A {}
|
||||
|
||||
interface B {}
|
||||
|
||||
interface C {}
|
||||
|
||||
interface I1 {
|
||||
T6294779c<? extends A> get();
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
T6294779c<? extends B> get();
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
T6294779c<? extends C> get();
|
||||
}
|
||||
|
||||
interface I4 extends I1, I2, I3 {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user