changeset 48846:ea2d4aa408e2 mvt

Tighten up a few loose ends in attribution and code generation for vwithfield (front-port from lworld)
author sadayapalam
date Mon, 12 Feb 2018 17:35:50 +0530
parents f4627cb71794
children 7b354aad53a1
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/langtools/tools/javac/diags/examples.not-yet.txt test/langtools/tools/javac/valhalla/values/CheckMakeDefault.out
diffstat 6 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Feb 12 17:14:42 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Feb 12 17:35:50 2018 +0530
@@ -298,13 +298,13 @@
                 log.error(pos, Errors.TryResourceMayNotBeAssigned(v));
             } else {
                 boolean complain = true;
-                /* Allow updates to blank final fields inside value factories.
+                /* Allow updates to blank final instance fields inside value factories.
                    This really results in copy on write and not mutation of the
                    final field
                 */
-                if (v.getKind() == ElementKind.FIELD && (v.flags() & HASINIT) == 0) {
+                if (v.getKind() == ElementKind.FIELD && (v.flags() & (HASINIT | STATIC)) == 0) {
                     if (env.enclMethod != null && (env.enclMethod.mods.flags & STATICVALUEFACTORY) != 0) {
-                        if (v.owner == env.enclMethod.sym.owner)
+                        if (v.owner == env.enclMethod.sym.owner && types.isValue(v.owner.type))
                             complain = false;
                     }
                 }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Mon Feb 12 17:14:42 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Mon Feb 12 17:35:50 2018 +0530
@@ -231,11 +231,15 @@
 
         if ((tree.mods.flags & STATICVALUEFACTORY) != 0) {
             if ((tree.mods.flags & STATIC) == 0) {
-                log.error(tree.pos(), "value.factory.must.be.static");
+                log.error(tree.pos(), Errors.ValueFactoryMustBeStatic);
             }
             final Type returnType = m.getReturnType();
-            if (returnType != null && returnType.tsym != m.owner) {
-                log.error(tree.restype != null ? tree.restype.pos() : tree.pos(), "type.found.req", returnType.tsym, m.owner);
+            if (returnType != null) {
+                if (returnType.tsym != m.owner) {
+                    log.error(tree.restype != null ? tree.restype.pos() : tree.pos(), "type.found.req", returnType.tsym, m.owner);
+                } else if (!types.isValue(m.owner.type)) {
+                    log.error(tree.pos(), Errors.ValueFactoryMustBeMemberOfValueType);
+                }
             }
         }
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Mon Feb 12 17:14:42 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java	Mon Feb 12 17:35:50 2018 +0530
@@ -2134,7 +2134,7 @@
                     boolean requireCopyOnWrite = false;
                     if (sym.kind == VAR && (sym.flags() & FINAL) != 0) {
                         if ((env.enclMethod.mods.flags & STATICVALUEFACTORY) != 0) {
-                            if (sym.owner == env.enclClass.sym)
+                            if (sym.owner == env.enclClass.sym && types.isValue(sym.owner.type))
                                 requireCopyOnWrite = true;
                         }
                     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Feb 12 17:14:42 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon Feb 12 17:35:50 2018 +0530
@@ -3245,4 +3245,7 @@
 
 # 0: symbol
 compiler.warn.cyclic.value.type.membership=\
-    cyclic value type membership involving {0}
\ No newline at end of file
+    cyclic value type membership involving {0}
+
+compiler.err.value.factory.must.be.member.of.value.type=\
+    value factory can only be a member of a value type
\ No newline at end of file
--- a/test/langtools/tools/javac/diags/examples.not-yet.txt	Mon Feb 12 17:14:42 2018 +0530
+++ b/test/langtools/tools/javac/diags/examples.not-yet.txt	Mon Feb 12 17:35:50 2018 +0530
@@ -173,3 +173,4 @@
 compiler.warn.value.field.must.be.final
 compiler.warn.value.may.not.extend
 compiler.warn.value.must.be.final
+compiler.err.value.factory.must.be.member.of.value.type
--- a/test/langtools/tools/javac/valhalla/values/CheckMakeDefault.out	Mon Feb 12 17:14:42 2018 +0530
+++ b/test/langtools/tools/javac/valhalla/values/CheckMakeDefault.out	Mon Feb 12 17:35:50 2018 +0530
@@ -1,6 +1,7 @@
+CheckMakeDefault.java:10:38: compiler.err.value.factory.must.be.member.of.value.type
 CheckMakeDefault.java:11:20: compiler.err.make.default.with.nonvalue
 CheckMakeDefault.java:28:16: compiler.err.make.default.in.nonfactory
 CheckMakeDefault.java:32:18: compiler.err.invalid.arguments.to.make.default
 CheckMakeDefault.java:33:19: compiler.err.make.default.with.nonvalue
 CheckMakeDefault.java:34:8: compiler.err.make.default.with.wrong.value.type: Point.SinnerValue
-5 errors
+6 errors