JDK-8210923 : JShell: support for switch expressions
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-09-19
  • Updated: 2018-11-06
  • Resolved: 2018-10-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b17Fixed
Related Reports
Relates :  
Relates :  
Description
Switch expressions in statements appear to work fine, but they are not recognized as expressions.  For example:

jshell> switch (day) {                                                                                                                                
   ...>     case MONDAY, FRIDAY, SUNDAY -> 6;                                                                                                         
   ...>     case TUESDAY                -> 7;                                                                                                         
   ...>     case THURSDAY, SATURDAY     -> 8;                                                                                                         
   ...>     case WEDNESDAY              -> 9;                                                                                                         
   ...> }                                                                                                                                             
|  Error:                                                                                                                                             
|  not a statement                                                                                                                                    
|      case MONDAY, FRIDAY, SUNDAY -> 6;                                                                                                              
|                                     ^                                                                                                               
|  Error:                                                                                                                                             
|  not a statement                                                                                                                                    
|      case TUESDAY                -> 7;                                                                                                              
|                                     ^                                                                                                               
|  Error:                                                                                                                                             
|  not a statement                                                                                                                                    
|      case THURSDAY, SATURDAY     -> 8;                                                                                                              
|                                     ^                                                                                                               
|  Error:                                                                                                                                             
|  not a statement                                                                                                                                    
|      case WEDNESDAY              -> 9;                                                                                                              
|                                     ^     

This is due to "switch" triggering the statement path of code analysis and parsing.

Completion needs to be addressed as well.  For example, 

switch (day) {
           case MONDAY, FRIDAY, SUNDAY -> 6;
           case TUESDAY                -> 7;
           case WEDNESDAY              -> 9;
           case THURSDAY, SATURDAY     -> 8;
       } + 100

does not include the "+ 100".  This may be hard to address.

-Robert

Comments
Sent for review 9/25/2018 -- pinging... Please review: Bug: https://bugs.openjdk.java.net/browse/JDK-8210923 Webrev: http://cr.openjdk.java.net/~rfield/8210923v0.webrev/ Thanks, Robert
16-10-2018