8016059: Cannot compile following lambda
authormcimadamore
Fri, 05 Jul 2013 11:03:04 +0100
changeset 18902 972298345a83
parent 18901 8309dd8e14d9
child 18903 99f42bd11bc2
8016059: Cannot compile following lambda 8016060: Lambda isn't compiled with return statement Summary: Spurious error triggered during unnecessary recovery round Reviewed-by: jjg, vromero
langtools/src/share/classes/com/sun/tools/javac/code/Type.java
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
langtools/test/tools/javac/lambda/TargetType75.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java	Fri Jul 05 11:02:17 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Type.java	Fri Jul 05 11:03:04 2013 +0100
@@ -78,6 +78,9 @@
     /** Constant type: special type to be used during recovery of deferred expressions. */
     public static final JCNoType recoveryType = new JCNoType();
 
+    /** Constant type: special type to be used for marking stuck trees. */
+    public static final JCNoType stuckType = new JCNoType();
+
     /** If this switch is turned on, the names of type variables
      *  and anonymous classes are printed with hashcodes appended.
      */
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jul 05 11:02:17 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jul 05 11:03:04 2013 +0100
@@ -555,11 +555,6 @@
                 }
             });
         }
-
-        @Override
-        protected Type check(DiagnosticPosition pos, Type found) {
-            return chk.checkNonVoid(pos, super.check(pos, found));
-        }
     }
 
     final ResultInfo statInfo;
@@ -1697,7 +1692,8 @@
                               diags.fragment("unexpected.ret.val"));
                 }
                 attribTree(tree.expr, env, env.info.returnResult);
-            } else if (!env.info.returnResult.pt.hasTag(VOID)) {
+            } else if (!env.info.returnResult.pt.hasTag(VOID) &&
+                    !env.info.returnResult.pt.hasTag(NONE)) {
                 env.info.returnResult.checkContext.report(tree.pos(),
                               diags.fragment("missing.ret.val"));
             }
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Jul 05 11:02:17 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Jul 05 11:03:04 2013 +0100
@@ -95,7 +95,7 @@
         make = TreeMaker.instance(context);
         types = Types.instance(context);
         Names names = Names.instance(context);
-        stuckTree = make.Ident(names.empty).setType(Type.noType);
+        stuckTree = make.Ident(names.empty).setType(Type.stuckType);
     }
 
     /** shared tree for stuck expressions */
@@ -649,7 +649,12 @@
          * a default expected type (j.l.Object).
          */
         private Type recover(DeferredType dt) {
-            dt.check(attr.new RecoveryInfo(deferredAttrContext));
+            dt.check(attr.new RecoveryInfo(deferredAttrContext) {
+                @Override
+                protected Type check(DiagnosticPosition pos, Type found) {
+                    return chk.checkNonVoid(pos, super.check(pos, found));
+                }
+            });
             return super.apply(dt);
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lambda/TargetType75.java	Fri Jul 05 11:03:04 2013 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 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 8016060 8016059
+ * @summary Lambda isn't compiled with return statement
+ * @compile TargetType75.java
+ */
+class TargetType75 {
+    interface P<X> {
+        void m(X x);
+    }
+
+    <Z> void m(P<Z> r, Z z) { }
+
+    void test() {
+        m(x->{ return; }, "");
+        m(x->System.out.println(""), "");
+    }
+}