changeset 2140:72daa9684315

8016060: Lambda isn't compiled with return statement 8016059: Cannot compile following lambda
author mcimadamore
date Thu, 06 Jun 2013 16:04:38 +0100
parents e95406cfa4aa
children eda4ff70411f
files src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java test/tools/javac/lambda/TargetType75.java
diffstat 4 files changed, 53 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Wed Jun 05 14:15:42 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Thu Jun 06 16:04:38 2013 +0100
@@ -77,6 +77,9 @@
 
     /** Constant type: special type to be used during recovery of deferred expressions. */
     public static final JCNoType recoveryType = new JCNoType(NONE);
+    
+    /** Constant type: special type to be for marking stuck trees. */
+    public static final JCNoType stuckType = new JCNoType(NONE);
 
     /** If this switch is turned on, the names of type variables
      *  and anonymous classes are printed with hashcodes appended.
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jun 05 14:15:42 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Jun 06 16:04:38 2013 +0100
@@ -549,11 +549,6 @@
                 }
             });
         }
-
-        @Override
-        protected Type check(DiagnosticPosition pos, Type found) {
-            return chk.checkNonVoid(pos, super.check(pos, found));
-        }
     }
 
     final ResultInfo statInfo;
@@ -1680,7 +1675,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/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Jun 05 14:15:42 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Jun 06 16:04:38 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 */
@@ -644,7 +644,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/test/tools/javac/lambda/TargetType75.java	Thu Jun 06 16:04:38 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(""), "");
+    }
+}