Integrated: 8253584: Redunant errors for partial member selects
Jan Lahoda
jlahoda at openjdk.java.net
Tue Sep 29 10:14:02 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.
This pull request has now been integrated.
Changeset: 86491a5f
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/86491a5f
Stats: 51 lines in 2 files changed: 48 ins; 0 del; 3 mod
8253584: Redunant errors for partial member selects
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/333
More information about the compiler-dev
mailing list