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

AST could be improved in presence of var types.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 10
    • Fix Version/s: 10
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b27

      Description

      There is a couple of minor issues with the AST model for var types:
      a) the JCVariableDecl.vartype is filled in for implicit lambda parameters and for-each variables, but not for ordinary local vars (like var i = 0;). This is inconsistent and can cause a real problem if Attr.postAttr is invoked, as it will add a JCErroneous for the missing vartype

      b) the SourcePosition.getStartPosition for a local var (without modifiers) points to the variable name, while it would be more consistent to point to the beginning of "var"

      There is also a minor issue in jshell:
      ---
      jshell> var x = () -> {};
      | Error:
      | incompatible types: java.lang.Object is not a functional interface
      | var x = () -> {};
      | ^------^
      ---

      And analogous error in javac:
      ---
      $ javac T.java
      T.java:3: error: cannot infer type for local variable broken
               var broken = () -> {};
                   ^
        (lambda expression needs an explicit target-type)
      1 error
      ---

        Attachments

          Activity

            People

            Assignee:
            jlahoda Jan Lahoda
            Reporter:
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: