changeset 50606:31b9bbb46aa9 lworld

lworld: Allow empty values under the option -XDallowEmptyValues
author sadayapalam
date Wed, 04 Jul 2018 11:31:06 +0530
parents efee31ddc695
children 1b791424da6b
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/langtools/tools/javac/valhalla/lworld-values/EmptyValueTest.java test/langtools/tools/javac/valhalla/lworld-values/EmptyValueTest.out
diffstat 3 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jul 03 14:41:47 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jul 04 11:31:06 2018 +0530
@@ -163,6 +163,7 @@
         sourceName = source.name;
         useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
         allowGenericsOverValues = options.isSet("allowGenericsOverValues");
+        allowEmptyValues = options.isSet("allowEmptyValues");
 
         statInfo = new ResultInfo(KindSelector.NIL, Type.noType);
         varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType);
@@ -205,6 +206,11 @@
     boolean allowGenericsOverValues;
 
     /**
+     * Switch: Allow value types with no instance state?
+     */
+    boolean allowEmptyValues;
+
+    /**
      * Switch: allow strings in switch?
      */
     boolean allowStringsInSwitch;
@@ -4809,7 +4815,7 @@
                     log.error(l.head.pos(), Errors.IclsCantHaveStaticDecl(c));
             }
         }
-        if (!hasInstanceFields && (c.flags() & VALUE) != 0) {
+        if (!allowEmptyValues && !hasInstanceFields && (c.flags() & VALUE) != 0) {
             log.error(tree.pos(), Errors.EmptyValueNotYet);
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/EmptyValueTest.java	Wed Jul 04 11:31:06 2018 +0530
@@ -0,0 +1,9 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary Test behavior with empty value type.
+ * @compile/fail/ref=EmptyValueTest.out -XDrawDiagnostics -XDdev EmptyValueTest.java
+ * @compile -XDrawDiagnostics -XDdev -XDallowEmptyValues EmptyValueTest.java
+ */
+public final __ByValue class EmptyValueTest {
+    static int x;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/EmptyValueTest.out	Wed Jul 04 11:31:06 2018 +0530
@@ -0,0 +1,2 @@
+EmptyValueTest.java:7:24: compiler.err.empty.value.not.yet
+1 error
\ No newline at end of file