Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8172453

JShell: choose more useful scratch variable type when result is intersection type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • tools
    • None

      This is follow-on to JDK-8171981.
      ---------
      I know that we are talking about synthetic variables where jshell stores expression values - but you can refer to these variables using $ID - so people referring to these variables will be able to see some edges and it would be nice to warn them that jshell picked something for them.

      Talking heuristics, I believe that, given an intersection like T1 & T2 ... Tn an acceptable normalization strategy is:

      * compute the minimal set of supertypes S = disjoint(T1, T2 ... Tn), where the set of disjoint types contains all types in T1 ... Tn for which there's no subtype in T1 ... Tn
      * if S contains just one type, use that type as the inferred type
      * if S contains multiple types, pick the first one

      I believe this heuristics should give good results and should also be deterministic. Of course this normalization should be done both at the top level (e.g. when the result of inference is an intersection type) and at the nested level (when the result of inference is some type like Foo<? extends A & B>).

      Maurizio

      -------

      That said, picking a more specific type is more likely to be unsurprising when they use the variable than if Object is picked. I played with picking any common class if there are any and any interface if not. .. would need predictable ordering for testing purposes.

      -Robert

            jlahoda Jan Lahoda
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: