6400189: raw types and inference
Fixed resolution problem with raw overriding (CCC) Reviewed-by: jjg
This commit is contained in:
parent
d0892edd69
commit
584c02dfa8
@ -216,7 +216,9 @@ public class Resolve {
|
||||
&&
|
||||
isAccessible(env, site)
|
||||
&&
|
||||
sym.isInheritedIn(site.tsym, types);
|
||||
sym.isInheritedIn(site.tsym, types)
|
||||
&&
|
||||
notOverriddenIn(site, sym);
|
||||
case PROTECTED:
|
||||
return
|
||||
(env.toplevel.packge == sym.owner.owner // fast special case
|
||||
@ -231,14 +233,23 @@ public class Resolve {
|
||||
&&
|
||||
isAccessible(env, site)
|
||||
&&
|
||||
// `sym' is accessible only if not overridden by
|
||||
// another symbol which is a member of `site'
|
||||
// (because, if it is overridden, `sym' is not strictly
|
||||
// speaking a member of `site'.)
|
||||
(sym.kind != MTH || sym.isConstructor() || sym.isStatic() ||
|
||||
((MethodSymbol)sym).implementation(site.tsym, types, true) == sym);
|
||||
notOverriddenIn(site, sym);
|
||||
default: // this case includes erroneous combinations as well
|
||||
return isAccessible(env, site);
|
||||
return isAccessible(env, site) && notOverriddenIn(site, sym);
|
||||
}
|
||||
}
|
||||
//where
|
||||
/* `sym' is accessible only if not overridden by
|
||||
* another symbol which is a member of `site'
|
||||
* (because, if it is overridden, `sym' is not strictly
|
||||
* speaking a member of `site'.)
|
||||
*/
|
||||
private boolean notOverriddenIn(Type site, Symbol sym) {
|
||||
if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
|
||||
return true;
|
||||
else {
|
||||
Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
|
||||
return (s2 == null || s2 == sym);
|
||||
}
|
||||
}
|
||||
//where
|
||||
@ -605,7 +616,7 @@ public class Resolve {
|
||||
Symbol mostSpecific(Symbol m1,
|
||||
Symbol m2,
|
||||
Env<AttrContext> env,
|
||||
Type site,
|
||||
final Type site,
|
||||
boolean allowBoxing,
|
||||
boolean useVarargs) {
|
||||
switch (m2.kind) {
|
||||
@ -661,21 +672,33 @@ public class Resolve {
|
||||
m2.erasure(types).getParameterTypes()))
|
||||
return new AmbiguityError(m1, m2);
|
||||
// both abstract, neither overridden; merge throws clause and result type
|
||||
Symbol result;
|
||||
Symbol mostSpecific;
|
||||
Type result2 = mt2.getReturnType();
|
||||
if (mt2.tag == FORALL)
|
||||
result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
|
||||
if (types.isSubtype(mt1.getReturnType(), result2)) {
|
||||
result = m1;
|
||||
mostSpecific = m1;
|
||||
} else if (types.isSubtype(result2, mt1.getReturnType())) {
|
||||
result = m2;
|
||||
mostSpecific = m2;
|
||||
} else {
|
||||
// Theoretically, this can't happen, but it is possible
|
||||
// due to error recovery or mixing incompatible class files
|
||||
return new AmbiguityError(m1, m2);
|
||||
}
|
||||
result = result.clone(result.owner);
|
||||
result.type = (Type)result.type.clone();
|
||||
MethodSymbol result = new MethodSymbol(
|
||||
mostSpecific.flags(),
|
||||
mostSpecific.name,
|
||||
null,
|
||||
mostSpecific.owner) {
|
||||
@Override
|
||||
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
|
||||
if (origin == site.tsym)
|
||||
return this;
|
||||
else
|
||||
return super.implementation(origin, types, checkResult);
|
||||
}
|
||||
};
|
||||
result.type = (Type)mostSpecific.type.clone();
|
||||
result.type.setThrown(chk.intersect(mt1.getThrownTypes(),
|
||||
mt2.getThrownTypes()));
|
||||
return result;
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 6400189
|
||||
* @summary raw types and inference
|
||||
* @author mcimadamore
|
||||
* @compile/fail/ref=T6400189a.out T6400189a.java -Xlint:unchecked -XDrawDiagnostics
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.annotation.Documented;
|
||||
|
||||
class T6400189a {
|
||||
Constructor c = null;
|
||||
Documented d = c.getAnnotation(Documented.class);
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
T6400189a.java:37:35: compiler.warn.unchecked.call.mbr.of.raw.type: <T>getAnnotation(java.lang.Class<T>), java.lang.reflect.Constructor
|
||||
T6400189a.java:37:35: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.annotation.Annotation, java.lang.annotation.Documented
|
||||
1 error
|
||||
1 warning
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 6400189
|
||||
* @summary raw types and inference
|
||||
* @author mcimadamore
|
||||
* @compile/fail/ref=T6400189b.out T6400189b.java -Xlint:unchecked -XDrawDiagnostics
|
||||
*/
|
||||
|
||||
class T6400189b<T> {
|
||||
|
||||
static class A {
|
||||
<T> T m(T6400189b<T> x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class B<T> extends A {
|
||||
<T> T m(T6400189b<T> x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void test(B b) {
|
||||
Integer i = b.m(new T6400189b<Integer>());
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
T6400189b.java:47:24: compiler.warn.unchecked.call.mbr.of.raw.type: <T>m(T6400189b<T>), T6400189b.B
|
||||
T6400189b.java:47:24: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Object, java.lang.Integer
|
||||
1 error
|
||||
1 warning
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 6400189
|
||||
* @summary raw types and inference
|
||||
* @author mcimadamore
|
||||
* @compile T6400189c.java
|
||||
*/
|
||||
|
||||
class T6400189c<T> {
|
||||
|
||||
static class A {
|
||||
<T> T m(T6400189c<T> x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class B<T> extends A {}
|
||||
|
||||
void test(B b) {
|
||||
Integer i = b.m(new T6400189c<Integer>());
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 6400189
|
||||
* @summary raw types and inference
|
||||
* @author mcimadamore
|
||||
* @compile T6400189d.java
|
||||
*/
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class T6400189c<T> {
|
||||
|
||||
interface A<X> extends Iterable<X> {
|
||||
Iterator<X> iterator();
|
||||
}
|
||||
|
||||
interface A2<Y> extends A<Y> {
|
||||
Iterator<Y> iterator();
|
||||
}
|
||||
|
||||
static abstract class B<Z> implements A<Z> {
|
||||
public abstract Iterator<Z> iterator();
|
||||
}
|
||||
|
||||
static abstract class C<W> extends B<W> implements A2<W> {
|
||||
Iterator<W> test() {
|
||||
return iterator();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user