6938454: Unable to determine generic type in program that compiles under Java 6
A redundant dubtyping check causes spurious inference failure Reviewed-by: jjg
This commit is contained in:
parent
bcbe3b2577
commit
541f7a7a41
@ -1694,8 +1694,22 @@ public class Attr extends JCTree.Visitor {
|
||||
//if the type of the instance creation expression is an interface
|
||||
//skip the method resolution step (JLS 15.12.2.7). The type to be
|
||||
//inferred is of the kind <X1,X2, ... Xn>C<X1,X2, ... Xn>
|
||||
clazztype = new ForAll(clazztype.tsym.type.allparams(),
|
||||
clazztype.tsym.type);
|
||||
clazztype = new ForAll(clazztype.tsym.type.allparams(), clazztype.tsym.type) {
|
||||
@Override
|
||||
public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
|
||||
switch (ck) {
|
||||
case EXTENDS: return types.getBounds(tv);
|
||||
default: return List.nil();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Type inst(List<Type> inferred, Types types) throws Infer.NoInstanceException {
|
||||
// check that inferred bounds conform to their bounds
|
||||
infer.checkWithinBounds(tvars,
|
||||
types.subst(tvars, tvars, inferred), Warner.noWarnings);
|
||||
return super.inst(inferred, types);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
//if the type of the instance creation expression is a class type
|
||||
//apply method resolution inference (JLS 15.12.2.7). The return type
|
||||
|
@ -256,7 +256,7 @@ public class Infer {
|
||||
UndetVar uv = (UndetVar) l.head;
|
||||
TypeVar tv = (TypeVar)uv.qtype;
|
||||
ListBuffer<Type> hibounds = new ListBuffer<Type>();
|
||||
for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS).prependList(types.getBounds(tv))) {
|
||||
for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS)) {
|
||||
if (!t.containsSome(that.tvars) && t.tag != BOT) {
|
||||
hibounds.append(t);
|
||||
}
|
||||
@ -280,7 +280,6 @@ public class Infer {
|
||||
// check bounds
|
||||
List<Type> targs = Type.map(undetvars, getInstFun);
|
||||
targs = types.subst(targs, that.tvars, targs);
|
||||
checkWithinBounds(that.tvars, targs, warn);
|
||||
return chk.checkType(warn.pos(), that.inst(targs, types), to);
|
||||
}
|
||||
|
||||
@ -398,7 +397,7 @@ public class Infer {
|
||||
UndetVar uv = (UndetVar)t;
|
||||
if (uv.qtype == tv) {
|
||||
switch (ck) {
|
||||
case EXTENDS: return uv.hibounds;
|
||||
case EXTENDS: return uv.hibounds.appendList(types.subst(types.getBounds(tv), all_tvars, inferredTypes));
|
||||
case SUPER: return uv.lobounds;
|
||||
case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
|
||||
}
|
||||
@ -458,7 +457,7 @@ public class Infer {
|
||||
|
||||
/** check that type parameters are within their bounds.
|
||||
*/
|
||||
private void checkWithinBounds(List<Type> tvars,
|
||||
void checkWithinBounds(List<Type> tvars,
|
||||
List<Type> arguments,
|
||||
Warner warn)
|
||||
throws InvalidInstanceException {
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010 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 6938454
|
||||
*
|
||||
* @summary Unable to determine generic type in program that compiles under Java 6
|
||||
* @author mcimadamore
|
||||
* @compile T6938454a.java
|
||||
*
|
||||
*/
|
||||
|
||||
class T6938454a {
|
||||
|
||||
static abstract class A { }
|
||||
|
||||
static class B extends A { }
|
||||
|
||||
B getB(B b) {
|
||||
return makeA(b);
|
||||
}
|
||||
|
||||
<X extends A, Y extends X> Y makeA(X x) {
|
||||
return (Y)new B();
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2010 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.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6938454
|
||||
*
|
||||
* @summary Unable to determine generic type in program that compiles under Java 6
|
||||
* @author mcimadamore
|
||||
* @compile T6938454b.java
|
||||
*
|
||||
*/
|
||||
|
||||
class T6938454b {
|
||||
|
||||
static interface A {}
|
||||
static interface B extends A {}
|
||||
static class C implements B {}
|
||||
|
||||
<T, R extends T, S extends R> List<R> m(List<T> l, S s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<B> test(List<A> la) {
|
||||
return m(la, new C());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user