8016059: Cannot compile following lambda
8016060: Lambda isn't compiled with return statement Spurious error triggered during unnecessary recovery round Reviewed-by: jjg, vromero
This commit is contained in:
parent
86f630b63e
commit
28b5759093
@ -78,6 +78,9 @@ public abstract class Type implements TypeMirror {
|
||||
/** 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.
|
||||
*/
|
||||
|
@ -555,11 +555,6 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Type check(DiagnosticPosition pos, Type found) {
|
||||
return chk.checkNonVoid(pos, super.check(pos, found));
|
||||
}
|
||||
}
|
||||
|
||||
final ResultInfo statInfo;
|
||||
@ -1697,7 +1692,8 @@ public class Attr extends JCTree.Visitor {
|
||||
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"));
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class DeferredAttr extends JCTree.Visitor {
|
||||
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 @@ public class DeferredAttr extends JCTree.Visitor {
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
41
langtools/test/tools/javac/lambda/TargetType75.java
Normal file
41
langtools/test/tools/javac/lambda/TargetType75.java
Normal file
@ -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(""), "");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user