jshell doesn't overwrite local variable type

Remi Forax forax at univ-mlv.fr
Thu Dec 26 18:18:29 UTC 2019


Another bug, if you defines a variable and then defines it again, for whatever reason, the type is lost.

$ jshell --enable-preview
|  Welcome to JShell -- Version 14-ea
|  For an introduction type: /help intro

jshell> /set feedback verbose
|  Feedback mode: verbose

jshell> record Square(int side) {
   ...>   public double surface() {
   ...>     return side * side;
   ...>   }
   ...> }
   ...> record Rectangle(int width, int height) {
   ...>   public double surface() {
   ...>     return width * height;
   ...>   }
   ...> }
   ...> 

jshell> var figures = List.of(new Square(2), new Rectangle(3, 4));
figures ==> [Square[side=2], Rectangle[width=3, height=4]]
|  created variable figures : List<Record>

jshell> interface Figure {
   ...>   public double surface();
   ...> }
   ...> 
   ...> record Square(int side) implements Figure {
   ...>   public double surface() {
   ...>     return side * side;
   ...>   }
   ...> }
   ...> record Rectangle(int width, int height) implements Figure {
   ...>   public double surface() {
   ...>     return width * height;
   ...>   }
   ...> }
|  created interface Figure

jshell> figures
figures ==> [Square[side=2], Rectangle[width=3, height=4]]
|  value of figures : List<Record>

jshell> var figures = List.of(new Square(2), new Rectangle(3, 4));
figures ==> [Square[side=2], Rectangle[width=3, height=4]]
|  modified variable figures : List<Record&Figure>
|    update overwrote variable figures : List<Record>

jshell> figures
figures ==> [Square[side=2], Rectangle[width=3, height=4]]
|  value of figures : List<Object>


why figures is not typed List<Object> ???

Rémi


More information about the amber-dev mailing list