8159680: Inference failure with unchecked subtyping and arrays
authormcimadamore
Fri, 17 Jun 2016 18:17:16 +0100
changeset 39100 5dc24593e3ae
parent 39099 80264cb25f29
child 39101 fd8a6392b7ea
8159680: Inference failure with unchecked subtyping and arrays Summary: Discrepancy in handling of capture conversion between Types.isSubtype and Types.isSubtypeUnchecked Reviewed-by: vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
langtools/test/tools/javac/generics/inference/8019824/T8019824.out
langtools/test/tools/javac/generics/inference/8159680/T8159680.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Jun 16 20:57:32 2016 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Fri Jun 17 18:17:16 2016 +0100
@@ -751,24 +751,24 @@
      * Is t an unchecked subtype of s?
      */
     public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) {
-        boolean result = isSubtypeUncheckedInternal(t, s, warn);
+        boolean result = isSubtypeUncheckedInternal(t, s, true, warn);
         if (result) {
             checkUnsafeVarargsConversion(t, s, warn);
         }
         return result;
     }
     //where
-        private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
+        private boolean isSubtypeUncheckedInternal(Type t, Type s, boolean capture, Warner warn) {
             if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) {
                 if (((ArrayType)t).elemtype.isPrimitive()) {
                     return isSameType(elemtype(t), elemtype(s));
                 } else {
-                    return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
+                    return isSubtypeUncheckedInternal(elemtype(t), elemtype(s), false, warn);
                 }
-            } else if (isSubtype(t, s)) {
+            } else if (isSubtype(t, s, capture)) {
                 return true;
             } else if (t.hasTag(TYPEVAR)) {
-                return isSubtypeUnchecked(t.getUpperBound(), s, warn);
+                return isSubtypeUncheckedInternal(t.getUpperBound(), s, false, warn);
             } else if (!s.isRaw()) {
                 Type t2 = asSuper(t, s.tsym);
                 if (t2 != null && t2.isRaw()) {
--- a/langtools/test/tools/javac/generics/inference/8019824/T8019824.out	Thu Jun 16 20:57:32 2016 +0000
+++ b/langtools/test/tools/javac/generics/inference/8019824/T8019824.out	Fri Jun 17 18:17:16 2016 +0100
@@ -1,2 +1,2 @@
-T8019824.java:9:25: compiler.err.cant.apply.symbol: kindname.method, make, java.lang.Class<C>, java.lang.Class<compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>>, kindname.class, T8019824, (compiler.misc.incompatible.eq.upper.bounds: C, compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>, T8019824.Foo<compiler.misc.type.captureof: 2, ?,B>)
+T8019824.java:9:25: compiler.err.cant.apply.symbol: kindname.method, make, java.lang.Class<C>, java.lang.Class<compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>>, kindname.class, T8019824, (compiler.misc.incompatible.eq.upper.bounds: C, compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>, T8019824.Foo<A,B>)
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/8159680/T8159680.java	Fri Jun 17 18:17:16 2016 +0100
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8159680
+ * @summary Inference failure with unchecked subtyping and arrays
+ * @compile T8159680.java
+ */
+
+class T8159680 {
+
+    static class Condition<T> {}
+
+    @SafeVarargs
+    static <T> Condition<T> allOf(Condition<? super T>... conditions) {
+        return null;
+    }
+
+    @SafeVarargs
+    static void test(Condition<? super Number>... conditions) {
+        allOf(conditions);
+    }
+}