Thu, 24 Jul 2008 10:35:38 +0100
6651719: Compiler crashes possibly during forward reference of TypeParameter
Summary: compiler should apply capture conversion when checking for bound conformance
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jul 23 19:55:30 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jul 24 10:35:38 2008 +0100 1.3 @@ -422,9 +422,7 @@ 1.4 * @param bs The bound. 1.5 */ 1.6 private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { 1.7 - if (a.isUnbound()) { 1.8 - return; 1.9 - } else if (a.tag != WILDCARD) { 1.10 + if (!(a instanceof CapturedType)) { 1.11 a = types.upperBound(a); 1.12 for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { 1.13 if (!types.isSubtype(a, l.head)) { 1.14 @@ -432,11 +430,24 @@ 1.15 return; 1.16 } 1.17 } 1.18 - } else if (a.isExtendsBound()) { 1.19 - if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings)) 1.20 - log.error(pos, "not.within.bounds", a); 1.21 - } else if (a.isSuperBound()) { 1.22 - if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound())) 1.23 + } 1.24 + else { 1.25 + CapturedType ct = (CapturedType)a; 1.26 + boolean ok = false; 1.27 + switch (ct.wildcard.kind) { 1.28 + case EXTENDS: 1.29 + ok = types.isCastable(bs.getUpperBound(), 1.30 + types.upperBound(a), 1.31 + Warner.noWarnings); 1.32 + break; 1.33 + case SUPER: 1.34 + ok = !types.notSoftSubtype(types.lowerBound(a), 1.35 + bs.getUpperBound()); 1.36 + break; 1.37 + case UNBOUND: 1.38 + ok = true; 1.39 + } 1.40 + if (!ok) 1.41 log.error(pos, "not.within.bounds", a); 1.42 } 1.43 } 1.44 @@ -776,7 +787,7 @@ 1.45 public void visitTypeApply(JCTypeApply tree) { 1.46 if (tree.type.tag == CLASS) { 1.47 List<Type> formals = tree.type.tsym.type.getTypeArguments(); 1.48 - List<Type> actuals = tree.type.getTypeArguments(); 1.49 + List<Type> actuals = types.capture(tree.type).getTypeArguments(); 1.50 List<JCExpression> args = tree.arguments; 1.51 List<Type> forms = formals; 1.52 ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>(); 1.53 @@ -792,7 +803,7 @@ 1.54 // bounds substed with actuals. 1.55 tvars_buf.append(types.substBound(((TypeVar)forms.head), 1.56 formals, 1.57 - Type.removeBounds(actuals))); 1.58 + actuals)); 1.59 1.60 args = args.tail; 1.61 forms = forms.tail; 1.62 @@ -811,10 +822,11 @@ 1.63 tvars = tvars_buf.toList(); 1.64 while (args.nonEmpty() && tvars.nonEmpty()) { 1.65 checkExtends(args.head.pos(), 1.66 - args.head.type, 1.67 + actuals.head, 1.68 tvars.head); 1.69 args = args.tail; 1.70 tvars = tvars.tail; 1.71 + actuals = actuals.tail; 1.72 } 1.73 1.74 // Check that this type is either fully parameterized, or
2.1 --- a/test/tools/javac/capture/Capture4.java Wed Jul 23 19:55:30 2008 -0700 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,44 +0,0 @@ 2.4 -/* 2.5 - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 - * 2.8 - * This code is free software; you can redistribute it and/or modify it 2.9 - * under the terms of the GNU General Public License version 2 only, as 2.10 - * published by the Free Software Foundation. 2.11 - * 2.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 - * version 2 for more details (a copy is included in the LICENSE file that 2.16 - * accompanied this code). 2.17 - * 2.18 - * You should have received a copy of the GNU General Public License version 2.19 - * 2 along with this work; if not, write to the Free Software Foundation, 2.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 - * 2.22 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 - * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 - * have any questions. 2.25 - */ 2.26 - 2.27 -/* 2.28 - * @test 2.29 - * @bug 4916650 2.30 - * @summary wildcards versus recursive F-bounds 2.31 - * @author gafter 2.32 - * 2.33 - * @compile -source 1.5 Capture4.java 2.34 - */ 2.35 - 2.36 -package capture4; 2.37 - 2.38 -class WildcardFBoundCheck { 2.39 - interface I4<T> {} 2.40 - 2.41 - static class C4<X extends I4<Y>, Y extends I4<X>> {} 2.42 - 2.43 - WildcardFBoundCheck() 2.44 - { 2.45 - C4<I4<?>,?> x2; // <<pass>> 2.46 - } 2.47 -}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/generics/wildcards/6651719/T6651719a.java Thu Jul 24 10:35:38 2008 +0100 3.3 @@ -0,0 +1,33 @@ 3.4 +/* 3.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 + * have any questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6651719 3.30 + * @summary Compiler crashes possibly during forward reference of TypeParameter 3.31 + * @compile T6651719a.java 3.32 + */ 3.33 + 3.34 +public class T6651719a<T extends S, S> { 3.35 + T6651719a<? extends T6651719a<?, ?>, ? extends T6651719a<?, ?>> crash = null; 3.36 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/generics/wildcards/6651719/T6651719b.java Thu Jul 24 10:35:38 2008 +0100 4.3 @@ -0,0 +1,37 @@ 4.4 +/* 4.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 4.24 + * have any questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 6651719 4.30 + * @summary Compiler crashes possibly during forward reference of TypeParameter 4.31 + * @compile T6651719b.java 4.32 + */ 4.33 +import java.util.*; 4.34 + 4.35 +public class T6651719b { 4.36 + <T> void m(T t, List<? super List<T>> list) {} 4.37 + void test(List<? super List<?>> list) { 4.38 + m("", list); 4.39 + } 4.40 +}