changeset 50604:32bf267ee453 lworld

8205686: [lworld] __WithField seems to have trouble if the value type is a generic type.
author sadayapalam
date Tue, 03 Jul 2018 15:21:14 +0530
parents 840330d6d1cb
children efee31ddc695
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/langtools/tools/javac/valhalla/lworld-values/WithFieldOfGenericType.java
diffstat 2 files changed, 63 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jul 03 13:26:16 2018 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jul 03 15:21:14 2018 +0530
@@ -1351,7 +1351,18 @@
                         (sym.flags() & STATIC) != 0 || !types.isValue(sym.owner.type)) {
                     log.error(tree.field.pos(), Errors.ValueInstanceFieldExpectedHere);
                 } else {
-                    capturedType = capture(sym.owner.type);
+                    Type ownType = sym.owner.type;
+                    switch(tree.field.getTag()) {
+                        case IDENT:
+                            JCIdent ident = (JCIdent) tree.field;
+                            ownType = ident.sym.owner.type;
+                            break;
+                        case SELECT:
+                            JCFieldAccess fieldAccess = (JCFieldAccess) tree.field;
+                            ownType = fieldAccess.selected.type;
+                            break;
+                    }
+                    capturedType = capture(ownType);
                 }
             }
             result = check(tree, capturedType, KindSelector.VAL, resultInfo);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/valhalla/lworld-values/WithFieldOfGenericType.java	Tue Jul 03 15:21:14 2018 +0530
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8205686
+ * @summary __WithField seems to have trouble if the value type is a generic type.
+ * @compile -XDrawDiagnostics -XDdev WithFieldOfGenericType.java
+ * @run main/othervm -XX:+EnableValhalla WithFieldOfGenericType
+ */
+
+public final __ByValue class WithFieldOfGenericType<E> {
+  private final boolean value;
+
+  public static <E> WithFieldOfGenericType<E> create() {
+    WithFieldOfGenericType<E> bug = __MakeDefault WithFieldOfGenericType<E>();
+    bug = __WithField(bug.value, true);
+    return bug;
+  }
+
+  private WithFieldOfGenericType() {
+    value = false;
+    throw new AssertionError();
+  }
+
+  public static void main(String[] args) {
+     WithFieldOfGenericType<String> w = create();
+     if (!w.toString().equals("[value class WithFieldOfGenericType, true]"))
+        throw new AssertionError("Withfield didn't work!");
+  }
+}