RFR: 8305671: javac rejects semicolons in compilation units with no imports
Jonathan Gibbons
jjg at openjdk.org
Mon Apr 17 23:45:44 UTC 2023
On Wed, 5 Apr 2023 18:37:05 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:
> The fix for [JDK-8027682](https://bugs.openjdk.org/browse/JDK-8027682) created a new bug in which a program like this:
>
> package p;;
>
> would be rejected.
>
> This is due to the previous fix swallowing all the semicolons. Instead, in the case of semicolons followed by EOF, it needs to swallow all but the last one.
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 3860:
> 3858: break;
> 3859: nextToken();
> 3860: }
This might work, but it "feels" wrong (as in, a hack) to leave an extra semicolon around.
Yes, a package statement must be followed by a semicolon (line 3835) but after that can't you slurp up all the extra semicolons, and only report them if there is an import statement, and ignore them if there are no imports?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13361#discussion_r1169356964
More information about the compiler-dev
mailing list