RFR: 8256149: Weird AST structure for incomplete member select

Jan Lahoda jlahoda at openjdk.java.net
Wed Nov 11 09:08:00 UTC 2020


Consider code like:
int i1 = "".
@Deprecated
void t1() {}

In current master, this will produce a somewhat twisted AST, and compile-time errors like:
E.java:2: error: <identifier> expected
int i = "".
           ^
E.java:3: error: illegal start of expression
@Deprecated void t() {}
^
E.java:3: error: ';' expected
@Deprecated void t() {}
           ^
3 errors

The reason is that `@Deprecated` is parsed as a type annotation following `"".<missing>`, which does not make much sense.

With this proposed patch, the AST is effectively the same as AST for:
int i1 = "".; //note the semicolon here
@Deprecated
void t1() {}

And the errors are much better as well:
E.java:2: error: <identifier> expected
int i = "".
           ^
1 error

-------------

Commit messages:
 - 8256149: Weird AST structure for incomplete member select

Changes: https://git.openjdk.java.net/jdk/pull/1159/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1159&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8256149
  Stats: 61 lines in 2 files changed: 60 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1159.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1159/head:pull/1159

PR: https://git.openjdk.java.net/jdk/pull/1159


More information about the compiler-dev mailing list