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

Type inference for addition is wrong

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • None
    • core-libs
    • None

      Addition is the only operator that can change its return type during Lowering. Consider:

      function f() {
          var i = 17;
          var j = 18;
          var k;
          for (;;) {
      k = i + j;
      i = {};
          }
          
      }
      Here, the addition i + j will be computed as ((double)i) + ((double)j) as that is the type used for integer additions (i = 17,j = 18), but when i is reassigned object, the addition remains, even though it should have been converted to a ScriptRuntime.ADD.

      function runScript() {
       function f() {
        [|2|];
        var i = ((object)17) [i (type=O) (slot=4)];
        [|3|];
        var j = 18 [j (type=I) (slot=5)];
        [|4|];
        var k [k (type=O) (slot=6)];
        [|5|];
         {
         for (; ; ) {
          [|6|];
          DISCARD(k = (object)((double)i) + ((double)j));
          [|7|];
          DISCARD(i = {});
         } [GOTO] [TERMINAL]
        } [GOTO] [TERMINAL]
       }

      We need to keep track of additions based on type changing source variables. I believe that the add operator is unique here as it is the only "either object or numeric return value" operator that exists.

            lagergren Marcus Lagergren
            lagergren Marcus Lagergren
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: