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

Specialized functions convert booleans to numbers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • None
    • b148
    • generic
    • generic

      Because the boolean type is considered narrower than numeric types in Nashorn it is possible to invoke builtin specialized functions that accept numeric params with boolean arguments. In many cases this leads to the correct result as arguments are converted to numbers anyway, but in the case of Array.prototype.concat and Array.prototype.push the result is wrong.

      var array = [].concat(true); // array is [1], should be [true]
      array.push(false); // array is [1, 0], should be [true, false]

      This only occurs with optimistic types enabled.

            hannesw Hannes Wallnoefer
            hannesw Hannes Wallnoefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: