changeset 754:83c22f23d80c

Compiler generates bad code when SAM-converting a lambda into an inner (abstract) class.
author mcimadamore
date Mon, 29 Nov 2010 12:04:48 +0000
parents 4335e2277cbd
children b635a35cbb89
files src/share/classes/com/sun/tools/javac/comp/Unlambda.java test/tools/javac/lambda/LambdaConv14.java
diffstat 2 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Mon Nov 15 17:07:07 2010 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Unlambda.java	Mon Nov 29 12:04:48 2010 +0000
@@ -34,6 +34,7 @@
 import com.sun.tools.javac.code.Symbol.*;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.code.Type.*;
+import org.omg.CORBA.INITIALIZE;
 
 
 /** This pass translates away lambda expressions
@@ -252,6 +253,17 @@
     }
 
     @Override
+    public void visitMethodDef(JCMethodDecl tree) {
+        if (tree.name == names.init &&
+                (currentClass.sym.flags() & Flags.LAMBDA) != 0) {
+            //skip synthetic constructor of lambda class
+            result = tree;
+            return;
+        }
+        super.visitMethodDef(tree);
+    }
+
+    @Override
     public void visitVarDef(final JCVariableDecl tree) {
         if (tree.sym.owner.kind == Kinds.MTH &&
                 tree.init != null &&
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/LambdaConv14.java	Mon Nov 29 12:04:48 2010 +0000
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2010, 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 test for inner SAM conversion
+ * @author  Maurizio Cimadamore
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableMethodHandles LambdaConv14
+ */
+
+public class LambdaConv14 {
+
+    static int assertionCount = 0;
+
+    static void assertTrue(boolean cond) {
+        assertionCount++;
+        if (!cond)
+            throw new AssertionError();
+    }
+
+    void test(){
+        SAM sam = #{ assertTrue(true); };
+        sam.test();
+    }
+
+    abstract class SAM {
+        abstract void test();
+    }
+
+    public static void main(String[] args) {
+        new LambdaConv14().test();
+        assertTrue(assertionCount == 1);
+    }
+}