@@ -47,10 +47,14 @@ Elm.Native.Array.make = function(elm) {
48 // Sets the value at the index i. Only the nodes leading to i will get
48 // Sets the value at the index i. Only the nodes leading to i will get
49 // copied and updated.
49 // copied and updated.
50− function set(i, item, a) {
50+ function set(i, item, array) {
51− if (length(a) <= i) {
51+ if (i < 0 || length(array) <= i) {
52− return a;
52+ return array;
54+ return unsafeSet(i, item, array);
57+ function unsafeSet(i, item, a) {
54 var newA = nodeCopy(a);
58 var newA = nodeCopy(a);
56 if (a.height == 0) {
60 if (a.height == 0) {
@@ -58,7 +62,7 @@ Elm.Native.Array.make = function(elm) {
59 var slot = getSlot(i, a);
63 var slot = getSlot(i, a);
60 var sub = slot > 0 ? a.lengths[slot-1] : 0;
64 var sub = slot > 0 ? a.lengths[slot-1] : 0;
61− newA.table[slot] = set(i - sub, item, a.table[slot]);
65+ newA.table[slot] = unsafeSet(i - sub, item, a.table[slot]);
63 return newA;
67 return newA;