changeset 52754:fbed49487ec4 concise-method-declarations

verifier error when inner class access field of enclosing class
author vromero
date Mon, 01 Oct 2018 19:37:00 -0700
parents 531a0335dc49
children ad90da891ae0
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java test/langtools/tools/javac/concise_methods/VerifierErrorAccessingFieldEnclosingClass.java
diffstat 2 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Oct 01 16:54:51 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Oct 01 19:37:00 2018 -0700
@@ -104,6 +104,7 @@
     private final boolean debugLower;
     private final boolean disableProtectedAccessors; // experimental
     private final PkgInfo pkginfoOpt;
+    private final TransTypes transTypes;
 
     protected Lower(Context context) {
         context.put(lowerKey, this);
@@ -128,6 +129,7 @@
             fromString(target.syntheticNameChar() + "closeResource");
 
         types = Types.instance(context);
+        transTypes = TransTypes.instance(context);
         Options options = Options.instance(context);
         debugLower = options.isSet("debuglower");
         pkginfoOpt = PkgInfo.get(options);
@@ -2547,7 +2549,7 @@
                             apply = make.at(tree.body.pos).Apply(List.nil(), qualifier, List.nil());
                             break;
                         case BOUND: case SUPER:
-                            qualifier = make.Select(make.QualIdent(TreeInfo.symbol(reference.expr)), reference.name);
+                            qualifier = make.Select(make.Ident(TreeInfo.symbol(reference.expr)), reference.name);
                             apply = make.at(tree.body.pos).Apply(List.nil(), qualifier, make.Idents(tree.params));
                             break;
                         case TOPLEVEL: case IMPLICIT_INNER:
@@ -2567,8 +2569,9 @@
                         case STATIC: case UNBOUND: case BOUND: case SUPER:
                             qualifier.type = tree.type;
                             qualifier.sym = reference.sym;
-                            apply.setType(tree.type.asMethodType().restype);
-                            expr = apply;
+                            Type mt = reference.sym.erasure(types);
+                            apply.setType(mt.asMethodType().restype);
+                            expr = transTypes.coerce(attrEnv, apply, types.erasure(tree.type.asMethodType().restype));
                             break;
                     }
                     if (!tree.type.asMethodType().restype.hasTag(VOID)) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/concise_methods/VerifierErrorAccessingFieldEnclosingClass.java	Mon Oct 01 19:37:00 2018 -0700
@@ -0,0 +1,47 @@
+/*
+ * 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
+ * @summary the verifier is failing when a field of the enclosing class is accessed from a concise method
+ * @modules jdk.compiler/com.sun.tools.javac.util
+ */
+
+import java.util.*;
+import static java.util.Objects.requireNonNull;
+
+public class VerifierErrorAccessingFieldEnclosingClass {
+    private final ArrayList<String> list = new ArrayList<>();
+
+    public void add(String student) -> list.add(requireNonNull(student));
+
+    public List<String> asList() -> new AbstractList<>() {
+        public int size() = list::size;
+        public String get(int index) = list::get;
+    };
+
+    public static void main(String[] args) {
+        var test = new VerifierErrorAccessingFieldEnclosingClass();
+        System.out.println(test.asList());
+    }
+}