# HG changeset patch # User mcimadamore # Date 1216892138 -3600 # Node ID 457a11ae2e843c31177455a02929a09b4f032415 # Parent 1d395a623f16c2f509afd6de80a977650bcd5652 6651719: Compiler crashes possibly during forward reference of TypeParameter Summary: compiler should apply capture conversion when checking for bound conformance Reviewed-by: jjg diff -r 1d395a623f16 -r 457a11ae2e84 langtools/src/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jul 23 19:55:30 2008 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jul 24 10:35:38 2008 +0100 @@ -422,9 +422,7 @@ * @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 l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { if (!types.isSubtype(a, l.head)) { @@ -432,11 +430,24 @@ 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 void visitTypeApply(JCTypeApply tree) { if (tree.type.tag == CLASS) { List formals = tree.type.tsym.type.getTypeArguments(); - List actuals = tree.type.getTypeArguments(); + List actuals = types.capture(tree.type).getTypeArguments(); List args = tree.arguments; List forms = formals; ListBuffer tvars_buf = new ListBuffer(); @@ -792,7 +803,7 @@ // 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 @@ 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 diff -r 1d395a623f16 -r 457a11ae2e84 langtools/test/tools/javac/capture/Capture4.java --- a/langtools/test/tools/javac/capture/Capture4.java Wed Jul 23 19:55:30 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright 2004 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 4916650 - * @summary wildcards versus recursive F-bounds - * @author gafter - * - * @compile -source 1.5 Capture4.java - */ - -package capture4; - -class WildcardFBoundCheck { - interface I4 {} - - static class C4, Y extends I4> {} - - WildcardFBoundCheck() - { - C4,?> x2; // <> - } -} diff -r 1d395a623f16 -r 457a11ae2e84 langtools/test/tools/javac/generics/wildcards/6651719/T6651719a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/wildcards/6651719/T6651719a.java Thu Jul 24 10:35:38 2008 +0100 @@ -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 { + T6651719a, ? extends T6651719a> crash = null; +} diff -r 1d395a623f16 -r 457a11ae2e84 langtools/test/tools/javac/generics/wildcards/6651719/T6651719b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/wildcards/6651719/T6651719b.java Thu Jul 24 10:35:38 2008 +0100 @@ -0,0 +1,37 @@ +/* + * 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 T6651719b.java + */ +import java.util.*; + +public class T6651719b { + void m(T t, List> list) {} + void test(List> list) { + m("", list); + } +}