6651719: Compiler crashes possibly during forward reference of TypeParameter
authormcimadamore
Thu, 24 Jul 2008 10:35:38 +0100
changeset 937 457a11ae2e84
parent 936 1d395a623f16
child 938 13aae74ca013
6651719: Compiler crashes possibly during forward reference of TypeParameter Summary: compiler should apply capture conversion when checking for bound conformance Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/test/tools/javac/capture/Capture4.java
langtools/test/tools/javac/generics/wildcards/6651719/T6651719a.java
langtools/test/tools/javac/generics/wildcards/6651719/T6651719b.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<Type> 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<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 @@
                     // 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
--- 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<T> {}
-
-    static class C4<X extends I4<Y>, Y extends I4<X>> {}
-
-    WildcardFBoundCheck()
-    {
-        C4<I4<?>,?> x2;  // <<pass>>
-    }
-}
--- /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<T extends S, S> {
+    T6651719a<? extends T6651719a<?, ?>, ? extends T6651719a<?, ?>> crash = null;
+}
--- /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 {
+    <T> void m(T t, List<? super List<T>> list) {}
+    void test(List<? super List<?>> list) {
+        m("", list);
+    }
+}