RFR: 8253584: Redunant errors for partial member selects
Vicente Romero
vromero at openjdk.java.net
Fri Sep 25 14:07:33 UTC 2020
On Thu, 24 Sep 2020 10:33:55 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> For code like:
> package t;
>
> class Test {
>
> void t() {
> if (true) {
> s().
> } else {
> }
> }
>
> String s() {
> return null;
> }
> }
>
> (note the missing member name after `s().`), javac will produce a number of compile-time errors:
> $ javac /tmp/Test.java
>
> s().
> ^
>
> s().
> ^
>
> } else {
> ^
>
> } else {
> ^
>
> String s() {
> ^
>
> }
> ^
> 6 errors
>
> The reason is that after not seeing an identifier after the `.` javac will skip the token that follows the dot. This
> was done to improve errors in https://bugs.openjdk.java.net/browse/JDK-8081769 . But here, reading the next token will
> skip the closing `}`, and the parser will de-synchronize with the braces, leading to the follow-up errors. The
> proposal here is to handle incorrect `.class` specially, and avoid reading the next token when an identifier is no
> specified in a member select, except when the next token is `class`. The errors with this patch are:
> $ javac /tmp/Test.java
>
> s().
> ^
>
> s().
> ^
> 2 errors
>
> This seems much better.
looks good to me
-------------
Marked as reviewed by vromero (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/333
More information about the compiler-dev
mailing list