changeset 49032:4d91ea65f463 lworld

8197791: Allow null to be cast into a value type (for now)
author sadayapalam
date Tue, 20 Feb 2018 16:01:54 +0530
parents f039363534f3
children 93dbb32d03b1
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java test/langtools/tools/javac/valhalla/lworld-values/CheckNullAssign.java test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.java test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.out
diffstat 4 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Feb 20 12:28:58 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Feb 20 16:01:54 2018 +0530
@@ -1107,7 +1107,7 @@
                      return isSubtypeNoCapture(t.getUpperBound(), s);
                  case BOT:
                      return
-                         s.hasTag(BOT) || (s.hasTag(CLASS) && !isValue(s)) ||
+                         s.hasTag(BOT) || s.hasTag(CLASS) ||
                          s.hasTag(ARRAY) || s.hasTag(TYPEVAR);
                  case WILDCARD: //we shouldn't be here - avoids crash (see 7034495)
                  case NONE:
@@ -1677,7 +1677,7 @@
 
             @Override
             public Boolean visitClassType(ClassType t, Type s) {
-                if (s.hasTag(ERROR) || s.hasTag(BOT) && !isValue(t))
+                if (s.hasTag(ERROR) || s.hasTag(BOT))
                     return true;
 
                 if (s.hasTag(TYPEVAR)) {
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckNullAssign.java	Tue Feb 20 12:28:58 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/CheckNullAssign.java	Tue Feb 20 16:01:54 2018 +0530
@@ -1,13 +1,12 @@
 /*
  * @test /nodynamiccopyright/
- * @summary Assignment of null to value types should be disallowed.
+ * @summary Check assignment of null to value types - legal scenarios.
  *
- * @compile/fail/ref=CheckNullAssign.out -XDrawDiagnostics CheckNullAssign.java
+ * @compile -XDrawDiagnostics CheckNullAssign.java
  */
 
 final __ByValue class CheckNullAssign {
     CheckNullAssign foo(CheckNullAssign cna) {
-        // All of the below involve subtype/assignability checks and should be rejected.
         cna = null;
         foo(null);
         if (null instanceof CheckNullAssign) {}
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.java	Tue Feb 20 12:28:58 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.java	Tue Feb 20 16:01:54 2018 +0530
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @summary null cannot be casted to and compared with value types.
+ * @summary Check that null can be casted to a value type; but cannot be compared with value types.
  *
  * @compile/fail/ref=CheckNullCastable.out -XDrawDiagnostics CheckNullCastable.java
  */
--- a/test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.out	Tue Feb 20 12:28:58 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.out	Tue Feb 20 16:01:54 2018 +0530
@@ -1,4 +1,3 @@
-CheckNullCastable.java:10:54: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullCastable)
-CheckNullCastable.java:11:17: compiler.err.incomparable.types: CheckNullCastable, compiler.misc.type.null
-CheckNullCastable.java:12:18: compiler.err.incomparable.types: compiler.misc.type.null, CheckNullCastable
-3 errors
+CheckNullCastable.java:11:17: compiler.err.value.does.not.support: !=
+CheckNullCastable.java:12:18: compiler.err.value.does.not.support: !=
+2 errors