Fri, 05 Jul 2013 11:03:04 +0100
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
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Fri Jul 05 11:02:17 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Fri Jul 05 11:03:04 2013 +0100 1.3 @@ -78,6 +78,9 @@ 1.4 /** Constant type: special type to be used during recovery of deferred expressions. */ 1.5 public static final JCNoType recoveryType = new JCNoType(); 1.6 1.7 + /** Constant type: special type to be used for marking stuck trees. */ 1.8 + public static final JCNoType stuckType = new JCNoType(); 1.9 + 1.10 /** If this switch is turned on, the names of type variables 1.11 * and anonymous classes are printed with hashcodes appended. 1.12 */
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Jul 05 11:02:17 2013 +0100 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Jul 05 11:03:04 2013 +0100 2.3 @@ -555,11 +555,6 @@ 2.4 } 2.5 }); 2.6 } 2.7 - 2.8 - @Override 2.9 - protected Type check(DiagnosticPosition pos, Type found) { 2.10 - return chk.checkNonVoid(pos, super.check(pos, found)); 2.11 - } 2.12 } 2.13 2.14 final ResultInfo statInfo; 2.15 @@ -1697,7 +1692,8 @@ 2.16 diags.fragment("unexpected.ret.val")); 2.17 } 2.18 attribTree(tree.expr, env, env.info.returnResult); 2.19 - } else if (!env.info.returnResult.pt.hasTag(VOID)) { 2.20 + } else if (!env.info.returnResult.pt.hasTag(VOID) && 2.21 + !env.info.returnResult.pt.hasTag(NONE)) { 2.22 env.info.returnResult.checkContext.report(tree.pos(), 2.23 diags.fragment("missing.ret.val")); 2.24 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Fri Jul 05 11:02:17 2013 +0100 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Fri Jul 05 11:03:04 2013 +0100 3.3 @@ -95,7 +95,7 @@ 3.4 make = TreeMaker.instance(context); 3.5 types = Types.instance(context); 3.6 Names names = Names.instance(context); 3.7 - stuckTree = make.Ident(names.empty).setType(Type.noType); 3.8 + stuckTree = make.Ident(names.empty).setType(Type.stuckType); 3.9 } 3.10 3.11 /** shared tree for stuck expressions */ 3.12 @@ -649,7 +649,12 @@ 3.13 * a default expected type (j.l.Object). 3.14 */ 3.15 private Type recover(DeferredType dt) { 3.16 - dt.check(attr.new RecoveryInfo(deferredAttrContext)); 3.17 + dt.check(attr.new RecoveryInfo(deferredAttrContext) { 3.18 + @Override 3.19 + protected Type check(DiagnosticPosition pos, Type found) { 3.20 + return chk.checkNonVoid(pos, super.check(pos, found)); 3.21 + } 3.22 + }); 3.23 return super.apply(dt); 3.24 } 3.25 }
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/lambda/TargetType75.java Fri Jul 05 11:03:04 2013 +0100 4.3 @@ -0,0 +1,41 @@ 4.4 +/* 4.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 8016060 8016059 4.30 + * @summary Lambda isn't compiled with return statement 4.31 + * @compile TargetType75.java 4.32 + */ 4.33 +class TargetType75 { 4.34 + interface P<X> { 4.35 + void m(X x); 4.36 + } 4.37 + 4.38 + <Z> void m(P<Z> r, Z z) { } 4.39 + 4.40 + void test() { 4.41 + m(x->{ return; }, ""); 4.42 + m(x->System.out.println(""), ""); 4.43 + } 4.44 +}