提交 9ed97c92 编写于 作者: M mcimadamore

6938454: Unable to determine generic type in program that compiles under Java 6

Summary: a redundant dubtyping check causes spurious inference failure
Reviewed-by: jjg
上级 f413b5a0
...@@ -1694,8 +1694,22 @@ public class Attr extends JCTree.Visitor { ...@@ -1694,8 +1694,22 @@ public class Attr extends JCTree.Visitor {
//if the type of the instance creation expression is an interface //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 //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> //inferred is of the kind <X1,X2, ... Xn>C<X1,X2, ... Xn>
clazztype = new ForAll(clazztype.tsym.type.allparams(), clazztype = new ForAll(clazztype.tsym.type.allparams(), clazztype.tsym.type) {
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 { } else {
//if the type of the instance creation expression is a class type //if the type of the instance creation expression is a class type
//apply method resolution inference (JLS 15.12.2.7). The return type //apply method resolution inference (JLS 15.12.2.7). The return type
......
...@@ -256,7 +256,7 @@ public class Infer { ...@@ -256,7 +256,7 @@ public class Infer {
UndetVar uv = (UndetVar) l.head; UndetVar uv = (UndetVar) l.head;
TypeVar tv = (TypeVar)uv.qtype; TypeVar tv = (TypeVar)uv.qtype;
ListBuffer<Type> hibounds = new ListBuffer<Type>(); 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) { if (!t.containsSome(that.tvars) && t.tag != BOT) {
hibounds.append(t); hibounds.append(t);
} }
...@@ -280,7 +280,6 @@ public class Infer { ...@@ -280,7 +280,6 @@ public class Infer {
// check bounds // check bounds
List<Type> targs = Type.map(undetvars, getInstFun); List<Type> targs = Type.map(undetvars, getInstFun);
targs = types.subst(targs, that.tvars, targs); targs = types.subst(targs, that.tvars, targs);
checkWithinBounds(that.tvars, targs, warn);
return chk.checkType(warn.pos(), that.inst(targs, types), to); return chk.checkType(warn.pos(), that.inst(targs, types), to);
} }
...@@ -398,7 +397,7 @@ public class Infer { ...@@ -398,7 +397,7 @@ public class Infer {
UndetVar uv = (UndetVar)t; UndetVar uv = (UndetVar)t;
if (uv.qtype == tv) { if (uv.qtype == tv) {
switch (ck) { 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 SUPER: return uv.lobounds;
case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil(); case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
} }
...@@ -458,7 +457,7 @@ public class Infer { ...@@ -458,7 +457,7 @@ public class Infer {
/** check that type parameters are within their bounds. /** check that type parameters are within their bounds.
*/ */
private void checkWithinBounds(List<Type> tvars, void checkWithinBounds(List<Type> tvars,
List<Type> arguments, List<Type> arguments,
Warner warn) Warner warn)
throws InvalidInstanceException { throws InvalidInstanceException {
......
/*
* 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();
}
}
/*
* 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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册