RFR: 8322532: JShell : Unnamed variable issue

Jan Lahoda jlahoda at openjdk.org
Tue Jan 2 15:21:06 UTC 2024


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!

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

Commit messages:
 - 8322532: JShell : Unnamed variable issue

Changes: https://git.openjdk.org/jdk/pull/17225/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17225&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8322532
  Stats: 8 lines in 2 files changed: 6 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/17225.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17225/head:pull/17225

PR: https://git.openjdk.org/jdk/pull/17225


More information about the kulla-dev mailing list