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

Better error recovery for parsing 'void' as a type of the lambda parameter

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 9
    • 8
    • tools
    • b01
    • Verified

    Description

      Consider an obviously erroneous code like this:
      ---
      public class Test {
          Runnable r = (void args) -> args;
      }
      ---

      Many errors are produced for this code:
      ---
      $ javac Test.java
      Test.java:2: error: illegal start of expression
          Runnable r = (void args) -> args;
                        ^
      Test.java:2: error: ')' expected
          Runnable r = (void args) -> args;
                            ^
      Test.java:2: error: ';' expected
          Runnable r = (void args) -> args;
                                 ^
      Test.java:2: error: illegal start of type
          Runnable r = (void args) -> args;
                                   ^
      4 errors
      ---

      And the AST for this is quite distorted (there is no lambda, etc.) The AST should ideally look like a lambda, whose parameter has type 'void', and limited number of more obvious errors should be produced.

      The reason for the current behavior is that the parser does not parse the lambda as a lambda, but rather as a parenthesized expression, which fails much worse. The AST is also inconsistent with the similar case where 'void' is used as a method parameter's type (but see JDK-8026374).

      This is with jdk8/tl/langtools:
      ---
      $ hg tip
      changeset: 2186:f3ca12d680f3
      tag: tip
      user: jfranck
      date: Mon Nov 11 17:26:09 2013 +0100
      summary: 8027375: javac asserts on nested erroneous annotations
      ---

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: