7005671: Regression: compiler accepts invalid cast from X[] to primitive array
authormcimadamore
Fri, 10 Dec 2010 15:23:42 +0000
changeset 7634 00834a375696
parent 7633 52b637b3b246
child 7635 e0a3aeefe4e7
7005671: Regression: compiler accepts invalid cast from X[] to primitive array Summary: regression in type conversion after 292 changes Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/code/Types.java
langtools/test/tools/javac/cast/7005671/T7005671.java
langtools/test/tools/javac/cast/7005671/T7005671.out
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Dec 09 19:53:03 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Dec 10 15:23:42 2010 +0000
@@ -1080,7 +1080,8 @@
                 case CLASS:
                     return isSubtype(t, s);
                 case ARRAY:
-                    if (elemtype(t).tag <= lastBaseTag) {
+                    if (elemtype(t).tag <= lastBaseTag ||
+                            elemtype(s).tag <= lastBaseTag) {
                         return elemtype(t).tag == elemtype(s).tag;
                     } else {
                         return visit(elemtype(t), elemtype(s));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/cast/7005671/T7005671.java	Fri Dec 10 15:23:42 2010 +0000
@@ -0,0 +1,32 @@
+/*
+ * @test /nodynamiccopyright/
+ * @author mcimadamore
+ * @bug     7005671
+ * @summary Regression: compiler accepts invalid cast from X[] to primitive array
+ * @compile/fail/ref=T7005671.out -XDrawDiagnostics T7005671.java
+ */
+
+class T7005671<X> {
+
+    void test1() {
+        Object o1 = (X[])(byte[])null;
+        Object o2 = (X[])(short[])null;
+        Object o3 = (X[])(int[])null;
+        Object o4 = (X[])(long[])null;
+        Object o5 = (X[])(float[])null;
+        Object o6 = (X[])(double[])null;
+        Object o7 = (X[])(char[])null;
+        Object o8 = (X[])(boolean[])null;
+    }
+
+    void test2() {
+        Object o1 = (byte[])(X[])null;
+        Object o2 = (short[])(X[])null;
+        Object o3 = (int[])(X[])null;
+        Object o4 = (long[])(X[])null;
+        Object o5 = (float[])(X[])null;
+        Object o6 = (double[])(X[])null;
+        Object o7 = (char[])(X[])null;
+        Object o8 = (boolean[])(X[])null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/cast/7005671/T7005671.out	Fri Dec 10 15:23:42 2010 +0000
@@ -0,0 +1,17 @@
+T7005671.java:12:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), byte[], X[]
+T7005671.java:13:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), short[], X[]
+T7005671.java:14:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), int[], X[]
+T7005671.java:15:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), long[], X[]
+T7005671.java:16:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), float[], X[]
+T7005671.java:17:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), double[], X[]
+T7005671.java:18:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), char[], X[]
+T7005671.java:19:26: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), boolean[], X[]
+T7005671.java:23:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], byte[]
+T7005671.java:24:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], short[]
+T7005671.java:25:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], int[]
+T7005671.java:26:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], long[]
+T7005671.java:27:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], float[]
+T7005671.java:28:31: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], double[]
+T7005671.java:29:29: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], char[]
+T7005671.java:30:32: compiler.err.prob.found.req: (compiler.misc.inconvertible.types), X[], boolean[]
+16 errors