RFR: 8322532: JShell : Unnamed variable issue

Adam Sotona asotona at openjdk.org
Wed Jan 3 13:33:39 UTC 2024


On Tue, 2 Jan 2024 15:16:41 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> The parser that estimates the type and completeness of snippets categorizes tokens to several categories. Underscore is currently not considered to be a token that may appear in an expression, and hence:
> 
> Func f = _ -> 0;
> 
> 
> is not recognized as a full valid variable declaration snippet, leading to further problems with splitting input into snippets, like:
> 
> jshell> interface Func { public void t(int i); }
>    ...> Func f = _ -> {};
>    ...> System.err.println("This should be printed, but is not!");
>    ...> 
> |  created interface Func
> f ==> $Lambda/0x00000000b3099000 at 2833cc44
> 
> jshell> 
> 
> 
> Note the output `This should be printed, but is not!` is missing.
> 
> The proposed change here is to mark underscore as an expression token, which then allows JShell to split the snippets correctly:
> 
> jshell> interface Func { public void t(int i); }
>    ...> Func f = _ -> {};
>    ...> System.err.println("This should be printed, but is not!");
> |  created interface Func
> f ==> $Lambda/0x0000000084099000 at 2833cc44
> This should be printed, but is not!

It looks good.

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

Marked as reviewed by asotona (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/17225#pullrequestreview-1802067800


More information about the kulla-dev mailing list