mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8041704: wrong error message when mixing lambda expression and inner class
Reviewed-by: vromero
This commit is contained in:
parent
378c3fe62f
commit
649331e00f
4 changed files with 32 additions and 5 deletions
|
@ -4678,17 +4678,31 @@ public class Attr extends JCTree.Visitor {
|
||||||
private void initTypeIfNeeded(JCTree that) {
|
private void initTypeIfNeeded(JCTree that) {
|
||||||
if (that.type == null) {
|
if (that.type == null) {
|
||||||
if (that.hasTag(METHODDEF)) {
|
if (that.hasTag(METHODDEF)) {
|
||||||
that.type = dummyMethodType();
|
that.type = dummyMethodType((JCMethodDecl)that);
|
||||||
} else {
|
} else {
|
||||||
that.type = syms.unknownType;
|
that.type = syms.unknownType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type dummyMethodType() {
|
/* Construct a dummy method type. If we have a method declaration,
|
||||||
return new MethodType(List.<Type>nil(), syms.unknownType,
|
* 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);
|
List.<Type>nil(), syms.methodClass);
|
||||||
}
|
}
|
||||||
|
private Type dummyMethodType() {
|
||||||
|
return dummyMethodType(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scan(JCTree tree) {
|
public void scan(JCTree tree) {
|
||||||
|
|
|
@ -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)
|
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…
Add table
Add a link
Reference in a new issue