提交 06a965cc 编写于 作者: P pgovereau

8041704: wrong error message when mixing lambda expression and inner class

Reviewed-by: vromero
上级 889cda1a
......@@ -4671,16 +4671,30 @@ public class Attr extends JCTree.Visitor {
private void initTypeIfNeeded(JCTree that) {
if (that.type == null) {
if (that.hasTag(METHODDEF)) {
that.type = dummyMethodType();
that.type = dummyMethodType((JCMethodDecl)that);
} else {
that.type = syms.unknownType;
}
}
}
/* Construct a dummy method type. If we have a method declaration,
* and the declared return type is void, then use that return type
* instead of UNKNOWN to avoid spurious error messages in lambda
* bodies (see:JDK-8041704).
*/
private Type dummyMethodType(JCMethodDecl md) {
Type restype = syms.unknownType;
if (md != null && md.restype.hasTag(TYPEIDENT)) {
JCPrimitiveTypeTree prim = (JCPrimitiveTypeTree)md.restype;
if (prim.typetag == VOID)
restype = syms.voidType;
}
return new MethodType(List.<Type>nil(), restype,
List.<Type>nil(), syms.methodClass);
}
private Type dummyMethodType() {
return new MethodType(List.<Type>nil(), syms.unknownType,
List.<Type>nil(), syms.methodClass);
return dummyMethodType(null);
}
@Override
......
CrashLambdaExpressionWithNonAccessibleIdTest.java:15:35: compiler.err.missing.ret.stmt
CrashLambdaExpressionWithNonAccessibleIdTest.java:14:17: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, CrashLambdaExpressionWithNonAccessibleIdTest, null)
2 errors
1 error
/**
* @test /nodynamiccopyright/
* @bug 8041704
* @summary wrong error message when mixing lambda expression and inner class
* @compile/fail/ref=ErrorMessageTest.out -XDrawDiagnostics ErrorMessageTest.java
*/
public class ErrorMessageTest {
void f(Runnable r) {
f(() -> { f(new MISSING() { public void run() {} }); });
}
}
ErrorMessageTest.java:10:25: compiler.err.cant.resolve.location: kindname.class, MISSING, , , (compiler.misc.location: kindname.class, ErrorMessageTest, null)
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册