RFR: 8253584: Redunant errors for partial member selects
Jan Lahoda
jlahoda at openjdk.java.net
Thu Sep 24 10:42:42 UTC 2020
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.
-------------
Commit messages:
- 8253584: Redunant errors for partial member selects
Changes: https://git.openjdk.java.net/jdk/pull/333/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=333&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8253584
Stats: 51 lines in 2 files changed: 48 ins; 0 del; 3 mod
Patch: https://git.openjdk.java.net/jdk/pull/333.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/333/head:pull/333
PR: https://git.openjdk.java.net/jdk/pull/333
More information about the compiler-dev
mailing list