mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-06 14:10:36 +00:00
8041704: wrong error message when mixing lambda expression and inner class
Reviewed-by: vromero
This commit is contained in:
parent
378c3fe62f
commit
649331e00f
@ -4678,16 +4678,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
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
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
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @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() {} }); });
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
ErrorMessageTest.java:10:25: compiler.err.cant.resolve.location: kindname.class, MISSING, , , (compiler.misc.location: kindname.class, ErrorMessageTest, null)
|
||||
1 error
|
||||
Loading…
x
Reference in New Issue
Block a user