changeset 53975:5ce4b99e7bf1 lworld

8218040: [lworld] [lworld] Restore value array covariant behavior by/as default.
author sadayapalam
date Wed, 30 Jan 2019 12:16:50 +0530
parents 86d31e02427e
children 991ba5f6900b
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java test/langtools/tools/javac/valhalla/lworld-values/NoncovariantArrayTest.java test/langtools/tools/javac/valhalla/lworld-values/NoncovariantArrayTest2.out
diffstat 3 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Jan 29 17:01:21 2019 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Wed Jan 30 12:16:50 2019 +0530
@@ -92,6 +92,7 @@
     final boolean allowDefaultMethods;
     final boolean mapCapturesToBounds;
     final boolean allowValueBasedClasses;
+    final boolean nonCovariantValueArrays;
     final Check chk;
     final Enter enter;
     JCDiagnostic.Factory diags;
@@ -123,6 +124,7 @@
         noWarnings = new Warner(null);
         Options options = Options.instance(context);
         allowValueBasedClasses = options.isSet("allowValueBasedClasses");
+        nonCovariantValueArrays = options.isSet("nonCovariantValueArrays");
     }
     // </editor-fold>
 
@@ -1075,8 +1077,10 @@
                     Type es = elemtype(s);
                     if (!isSubtypeUncheckedInternal(et, es, false, warn))
                         return false;
-                    if (isValue(et) || isValue(es)) {
-                        return isSameType(erasure(et), erasure(es));
+                    if (nonCovariantValueArrays) {
+                        if (isValue(et) || isValue(es)) {
+                            return isSameType(erasure(et), erasure(es));
+                        }
                     }
                     return true;
                 }
@@ -1880,8 +1884,10 @@
                         Type es = elemtype(s);
                         if (!visit(et, es))
                             return false;
-                        if (isValue(et) || isValue(es)) {
-                            return isSameType(erasure(et), erasure(es));
+                        if (nonCovariantValueArrays) {
+                            if (isValue(et) || isValue(es)) {
+                                return isSameType(erasure(et), erasure(es));
+                            }
                         }
                         return true;
                     }
--- a/test/langtools/tools/javac/valhalla/lworld-values/NoncovariantArrayTest.java	Tue Jan 29 17:01:21 2019 -0800
+++ b/test/langtools/tools/javac/valhalla/lworld-values/NoncovariantArrayTest.java	Wed Jan 30 12:16:50 2019 +0530
@@ -1,10 +1,10 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 8215507
+ * @bug 8215507 8218040
  * @summary javac should forbid conversion from value array to Object[]
- * @compile/fail/ref=NoncovariantArrayTest.out -XDrawDiagnostics -XDdev NoncovariantArrayTest.java
+ * @compile/fail/ref=NoncovariantArrayTest.out -XDnonCovariantValueArrays -XDrawDiagnostics -XDdev NoncovariantArrayTest.java
+ * @compile/fail/ref=NoncovariantArrayTest2.out -XDrawDiagnostics -XDdev NoncovariantArrayTest.java
  */
-
 public class NoncovariantArrayTest { 
     static final value class V { 
         public final int v1; 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/NoncovariantArrayTest2.out	Wed Jan 30 12:16:50 2019 +0530
@@ -0,0 +1,4 @@
+NoncovariantArrayTest.java:16:33: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int[], java.lang.Object[])
+NoncovariantArrayTest.java:17:14: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int[], java.lang.Object[])
+NoncovariantArrayTest.java:22:14: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Object[], NoncovariantArrayTest.V[])
+3 errors
\ No newline at end of file