JDK-8140640 : Confusing compilation error for lambda
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2015-10-28
  • Updated: 2018-05-21
  • Resolved: 2018-05-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_minorResolved
Related Reports
Relates :  
Relates :  
Description
After JDK-8131742 was fixed the following code with syntax error won't compile any more:

class A {
    static Runnable r = (__GAR BAGE__.this) -> { };
} 

Compilation error:
A.java:2: error: ',', ')', or '[' expected
    static Runnable r = (__GAR BAGE__.this) -> { };
                                     ^
A.java:2: error: as of release 8, 'this' is allowed as the parameter name for the receiver type only, which has to be the first parameter
    static Runnable r = (__GAR BAGE__.this) -> { };
                                      ^
A.java:2: error: ';' expected
    static Runnable r = (__GAR BAGE__.this) -> { };
                                          ^
3 errors

I believe the second message is confusing because receiver parameter is not allowed in FormalParameters of a lambda expression (JLS 15.27.1. Lambda Parameters) at all.
Comments
This has been addressed as part of the 'var' in lambda effort - the new message is: error: as of release 8, 'this' is allowed as the parameter name for the receiver type only static Runnable r = (__GAR BAGE__.this) -> { }; ^ which has to be the first parameter, and cannot be a lambda parameter 1 error
21-05-2018