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

AST could be improved in presence of var types.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • 10
    • tools
    • None
    • b27

      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
      ---

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

              Created:
              Updated:
              Resolved: