RFR: 8129418: JShell: better highlighting of errors in imports on demand
Jan Lahoda
jlahoda at openjdk.org
Sat May 4 19:25:06 UTC 2024
On Thu, 2 May 2024 23:42:38 GMT, Nizar Benalla <duke at openjdk.org> wrote:
> When Type-Import-on-Demand fails, we now point the position of the first incorrect PackageOrTypeName which clearly isn't package, a class,or an interface.
>
> old behavior:
>
> | Welcome to JShell -- Version 22.0.1
> | For an introduction type: /help intro
>
> jshell> import unknown.*;
> | Error:
> | package unknown does not exist
> | import unknown.*;
> | ^
>
> New behavior:
>
> | Welcome to JShell -- Version 23-internal
> | For an introduction type: /help intro
>
> jshell> import unknown.*;
> | Error:
> | package unknown does not exist
> | import unknown.*;
> | ^-----^
>
>
>
> jshell> import unknown.unknown.unknown.*;
> | Error:
> | package unknown.unknown.unknown does not exist
> | import unknown.unknown.unknown.*;
> | ^---------------------^
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 4428:
> 4426: if (tsym.kind == PCK && tsym.members().isEmpty() &&
> 4427: !(Feature.IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES.allowedInSource(source) && tsym.exists())) {
> 4428: log.error(DiagnosticFlag.RESOLVE_ERROR, imp.qualid.selected.pos, Errors.DoesntExist(tsym));
I would suggest to use `.pos()`, instead of `.pos`. The former returns a `DiagnosticPosition`, with start/end/preferred positions, while the later just an integer. I.e. in JShell, the former will do:
jshell> import unknown.unknown.unknown.*;
| Error:
| package unknown.unknown.unknown does not exist
| import unknown.unknown.unknown.*;
| ^---------------------^
while the latter will do:
jshell> import unknown.unknown.unknown.*;
| Error:
| package unknown.unknown.unknown does not exist
| import unknown.unknown.unknown.*;
| ^
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19073#discussion_r1588861114
More information about the compiler-dev
mailing list