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

Tue, 27 May 2014 21:15:06 +0100

author
pgovereau
date
Tue, 27 May 2014 21:15:06 +0100
changeset 2399
f4254623c54e
parent 2398
7c925f35f81c
child 2400
0e026d3f2786

8041704: wrong error message when mixing lambda expression and inner class
Reviewed-by: vromero

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8041704/ErrorMessageTest.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/T8041704/ErrorMessageTest.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri May 23 16:27:22 2014 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue May 27 21:15:06 2014 +0100
     1.3 @@ -4671,16 +4671,30 @@
     1.4          private void initTypeIfNeeded(JCTree that) {
     1.5              if (that.type == null) {
     1.6                  if (that.hasTag(METHODDEF)) {
     1.7 -                    that.type = dummyMethodType();
     1.8 +                    that.type = dummyMethodType((JCMethodDecl)that);
     1.9                  } else {
    1.10                      that.type = syms.unknownType;
    1.11                  }
    1.12              }
    1.13          }
    1.14  
    1.15 +        /* Construct a dummy method type. If we have a method declaration,
    1.16 +         * and the declared return type is void, then use that return type
    1.17 +         * instead of UNKNOWN to avoid spurious error messages in lambda
    1.18 +         * bodies (see:JDK-8041704).
    1.19 +         */
    1.20 +        private Type dummyMethodType(JCMethodDecl md) {
    1.21 +            Type restype = syms.unknownType;
    1.22 +            if (md != null && md.restype.hasTag(TYPEIDENT)) {
    1.23 +                JCPrimitiveTypeTree prim = (JCPrimitiveTypeTree)md.restype;
    1.24 +                if (prim.typetag == VOID)
    1.25 +                    restype = syms.voidType;
    1.26 +            }
    1.27 +            return new MethodType(List.<Type>nil(), restype,
    1.28 +                                  List.<Type>nil(), syms.methodClass);
    1.29 +        }
    1.30          private Type dummyMethodType() {
    1.31 -            return new MethodType(List.<Type>nil(), syms.unknownType,
    1.32 -                            List.<Type>nil(), syms.methodClass);
    1.33 +            return dummyMethodType(null);
    1.34          }
    1.35  
    1.36          @Override
     2.1 --- a/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out	Fri May 23 16:27:22 2014 +0100
     2.2 +++ b/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out	Tue May 27 21:15:06 2014 +0100
     2.3 @@ -1,3 +1,2 @@
     2.4 -CrashLambdaExpressionWithNonAccessibleIdTest.java:15:35: compiler.err.missing.ret.stmt
     2.5  CrashLambdaExpressionWithNonAccessibleIdTest.java:14:17: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, CrashLambdaExpressionWithNonAccessibleIdTest, null)
     2.6 -2 errors
     2.7 +1 error
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/lambda/T8041704/ErrorMessageTest.java	Tue May 27 21:15:06 2014 +0100
     3.3 @@ -0,0 +1,12 @@
     3.4 +/**
     3.5 + * @test /nodynamiccopyright/
     3.6 + * @bug 8041704
     3.7 + * @summary wrong error message when mixing lambda expression and inner class
     3.8 + * @compile/fail/ref=ErrorMessageTest.out -XDrawDiagnostics ErrorMessageTest.java
     3.9 + */
    3.10 +
    3.11 +public class ErrorMessageTest {
    3.12 +    void f(Runnable r) {
    3.13 +        f(() -> { f(new MISSING() { public void run() {} }); });
    3.14 +    }
    3.15 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/lambda/T8041704/ErrorMessageTest.out	Tue May 27 21:15:06 2014 +0100
     4.3 @@ -0,0 +1,2 @@
     4.4 +ErrorMessageTest.java:10:25: compiler.err.cant.resolve.location: kindname.class, MISSING, , , (compiler.misc.location: kindname.class, ErrorMessageTest, null)
     4.5 +1 error

mercurial