Integrated: 8322532: JShell : Unnamed variable issue
Jan Lahoda
jlahoda at openjdk.org
Fri Jan 5 11:37:32 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!
This pull request has now been integrated.
Changeset: f0cfd361
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/f0cfd361bd6a98dc1192dab2116fdd3904f130f8
Stats: 8 lines in 2 files changed: 6 ins; 0 del; 2 mod
8322532: JShell : Unnamed variable issue
Reviewed-by: asotona
-------------
PR: https://git.openjdk.org/jdk/pull/17225
More information about the kulla-dev
mailing list