6651719: Compiler crashes possibly during forward reference of TypeParameter
Compiler should apply capture conversion when checking for bound conformance Reviewed-by: jjg
This commit is contained in:
parent
f3eff961d3
commit
fec04e0a18
langtools
src/share/classes/com/sun/tools/javac/comp
test/tools/javac/generics/wildcards/6651719
@ -422,9 +422,7 @@ public class Check {
|
||||
* @param bs The bound.
|
||||
*/
|
||||
private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) {
|
||||
if (a.isUnbound()) {
|
||||
return;
|
||||
} else if (a.tag != WILDCARD) {
|
||||
if (!(a instanceof CapturedType)) {
|
||||
a = types.upperBound(a);
|
||||
for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) {
|
||||
if (!types.isSubtype(a, l.head)) {
|
||||
@ -432,11 +430,24 @@ public class Check {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (a.isExtendsBound()) {
|
||||
if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings))
|
||||
log.error(pos, "not.within.bounds", a);
|
||||
} else if (a.isSuperBound()) {
|
||||
if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound()))
|
||||
}
|
||||
else {
|
||||
CapturedType ct = (CapturedType)a;
|
||||
boolean ok = false;
|
||||
switch (ct.wildcard.kind) {
|
||||
case EXTENDS:
|
||||
ok = types.isCastable(bs.getUpperBound(),
|
||||
types.upperBound(a),
|
||||
Warner.noWarnings);
|
||||
break;
|
||||
case SUPER:
|
||||
ok = !types.notSoftSubtype(types.lowerBound(a),
|
||||
bs.getUpperBound());
|
||||
break;
|
||||
case UNBOUND:
|
||||
ok = true;
|
||||
}
|
||||
if (!ok)
|
||||
log.error(pos, "not.within.bounds", a);
|
||||
}
|
||||
}
|
||||
@ -776,7 +787,7 @@ public class Check {
|
||||
public void visitTypeApply(JCTypeApply tree) {
|
||||
if (tree.type.tag == CLASS) {
|
||||
List<Type> formals = tree.type.tsym.type.getTypeArguments();
|
||||
List<Type> actuals = tree.type.getTypeArguments();
|
||||
List<Type> actuals = types.capture(tree.type).getTypeArguments();
|
||||
List<JCExpression> args = tree.arguments;
|
||||
List<Type> forms = formals;
|
||||
ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>();
|
||||
@ -792,7 +803,7 @@ public class Check {
|
||||
// bounds substed with actuals.
|
||||
tvars_buf.append(types.substBound(((TypeVar)forms.head),
|
||||
formals,
|
||||
Type.removeBounds(actuals)));
|
||||
actuals));
|
||||
|
||||
args = args.tail;
|
||||
forms = forms.tail;
|
||||
@ -811,10 +822,11 @@ public class Check {
|
||||
tvars = tvars_buf.toList();
|
||||
while (args.nonEmpty() && tvars.nonEmpty()) {
|
||||
checkExtends(args.head.pos(),
|
||||
args.head.type,
|
||||
actuals.head,
|
||||
tvars.head);
|
||||
args = args.tail;
|
||||
tvars = tvars.tail;
|
||||
actuals = actuals.tail;
|
||||
}
|
||||
|
||||
// Check that this type is either fully parameterized, or
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 6651719
|
||||
* @summary Compiler crashes possibly during forward reference of TypeParameter
|
||||
* @compile T6651719a.java
|
||||
*/
|
||||
|
||||
public class T6651719a<T extends S, S> {
|
||||
T6651719a<? extends T6651719a<?, ?>, ? extends T6651719a<?, ?>> crash = null;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* 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
|
||||
@ -23,22 +23,15 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4916650
|
||||
* @summary wildcards versus recursive F-bounds
|
||||
* @author gafter
|
||||
*
|
||||
* @compile -source 1.5 Capture4.java
|
||||
* @bug 6651719
|
||||
* @summary Compiler crashes possibly during forward reference of TypeParameter
|
||||
* @compile T6651719b.java
|
||||
*/
|
||||
import java.util.*;
|
||||
|
||||
package capture4;
|
||||
|
||||
class WildcardFBoundCheck {
|
||||
interface I4<T> {}
|
||||
|
||||
static class C4<X extends I4<Y>, Y extends I4<X>> {}
|
||||
|
||||
WildcardFBoundCheck()
|
||||
{
|
||||
C4<I4<?>,?> x2; // <<pass>>
|
||||
public class T6651719b {
|
||||
<T> void m(T t, List<? super List<T>> list) {}
|
||||
void test(List<? super List<?>> list) {
|
||||
m("", list);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user