Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8140640

Confusing compilation error for lambda

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 9
    • Fix Version/s: tbd_minor
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Introduced In Build:
      b76
    • Introduced In Version:
      9

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                snikandrova Svetlana Nikandrova (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: