RFR: 8129418: JShell: better highlighting of errors in imports on demand

Nizar Benalla duke at openjdk.org
Sat May 4 19:25:06 UTC 2024


On Fri, 3 May 2024 07:49:06 GMT, Jan Lahoda <jlahoda 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.*;
> |                        ^

Fixed in [c01e851](https://github.com/openjdk/jdk/pull/19073/commits/c01e851fdfb95977a1898c7fabee119ee230ab83), thanks.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19073#discussion_r1590096705


More information about the compiler-dev mailing list