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

Type inference for addition is wrong

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Fixed
    • None
    • 8
    • core-libs
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: