changeset 48847:7b354aad53a1 mvt

Additional tests for vwithfield (front-port from lworld)
author sadayapalam
date Mon, 12 Feb 2018 17:37:33 +0530
parents ea2d4aa408e2
children d94e80bbddca
files test/langtools/tools/javac/valhalla/values/CheckStaticFactoryNonValueClass.java test/langtools/tools/javac/valhalla/values/CheckStaticFactoryNonValueClass.out test/langtools/tools/javac/valhalla/values/CheckStaticFinalAssign.java test/langtools/tools/javac/valhalla/values/CheckStaticFinalAssign.out
diffstat 4 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/values/CheckStaticFactoryNonValueClass.java	Mon Feb 12 17:37:33 2018 +0530
@@ -0,0 +1,19 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary Check that a value factory may not be declared for a non-value class
+ * @compile/fail/ref=CheckStaticFactoryNonValueClass.out -XDenableValueTypes -XDrawDiagnostics -XDdev CheckStaticFactoryNonValueClass.java
+ */
+
+final class CheckStaticFactoryNonValueClass {
+    final int x;
+
+    __ValueFactory CheckStaticFactoryNonValueClass() { // error
+        x = 10;
+    }
+
+    static __ValueFactory CheckStaticFactoryNonValueClass foo() { // error
+       CheckStaticFactoryNonValueClass x = new CheckStaticFactoryNonValueClass();
+       x.x = 100; // error.
+       return x;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/values/CheckStaticFactoryNonValueClass.out	Mon Feb 12 17:37:33 2018 +0530
@@ -0,0 +1,4 @@
+CheckStaticFactoryNonValueClass.java:10:20: compiler.err.mod.not.allowed.here: staticvaluefactory
+CheckStaticFactoryNonValueClass.java:14:59: compiler.err.value.factory.must.be.member.of.value.type
+CheckStaticFactoryNonValueClass.java:16:9: compiler.err.cant.assign.val.to.final.var: x
+3 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/values/CheckStaticFinalAssign.java	Mon Feb 12 17:37:33 2018 +0530
@@ -0,0 +1,18 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary Check that a static final field may not be modified in a value factory
+ * @compile/fail/ref=CheckStaticFinalAssign.out -XDenableValueTypes -XDrawDiagnostics -XDdev CheckStaticFinalAssign.java
+ */
+
+__ByValue final class CheckStaticFinalAssign {
+    static final int x;
+    static {
+        x = 10;
+    }
+
+    static __ValueFactory CheckStaticFinalAssign foo() {
+       CheckStaticFinalAssign x = __MakeDefault CheckStaticFinalAssign();
+       x.x = 100;
+       return x;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/values/CheckStaticFinalAssign.out	Mon Feb 12 17:37:33 2018 +0530
@@ -0,0 +1,2 @@
+CheckStaticFinalAssign.java:15:9: compiler.err.cant.assign.val.to.final.var: x
+1 error