Repository: effekt-lang/effekt (scala)

Issue:
JS backend: Array.toList drops first element
Executing `.toList` on an array drops the first element.

## Example
For the program:
```effekt
import mutable/array

def main() = {
  val array = arrayFromList([1,2,3]);
  println(array.toList)
}
```
we get the output:
```
Cons(2, Cons(3, Nil()))
```

Pull request description:
Fixes #319.

Patch:
diff --git a/examples/pos/issue319.check b/examples/pos/issue319.check
new file mode 100644
index 000000000..385e54d12
--- /dev/null
+++ b/examples/pos/issue319.check
@@ -0,0 +1,1 @@
+Cons(1, Cons(2, Cons(3, Nil())))
diff --git a/examples/pos/issue319.effekt b/examples/pos/issue319.effekt
new file mode 100644
index 000000000..43647ed97
--- /dev/null
+++ b/examples/pos/issue319.effekt
@@ -0,0 +1,6 @@
+import mutable/array
+
+def main() = {
+  val array = arrayFromList([1,2,3]);
+  println(array.toList)
+}
diff --git a/libraries/js/mutable/array.effekt b/libraries/js/mutable/array.effekt
index cc4d47981..0f3443d84 100644
--- a/libraries/js/mutable/array.effekt
+++ b/libraries/js/mutable/array.effekt
@@ -52,7 +52,7 @@ extern pure def copy[T](arr: Array[T]): Array[T] =
 def toList[T](arr: Array[T]): List[T] = {
   var i = arr.size - 1;
   var l = Nil[T]()
-  while (i > 0) {
+  while (i >= 0) {
     l = Cons(unsafeGet(arr, i), l)
     i = i - 1
   }


Test patch:
diff --git a/effekt/jvm/src/test/scala/effekt/ChezSchemeTests.scala b/effekt/jvm/src/test/scala/effekt/ChezSchemeTests.scala
index b6c1dc54b..e1a3c291d 100644
--- a/effekt/jvm/src/test/scala/effekt/ChezSchemeTests.scala
+++ b/effekt/jvm/src/test/scala/effekt/ChezSchemeTests.scala
@@ -23,6 +23,7 @@ abstract class ChezSchemeTests extends EffektTests {
     examplesDir / "ml",
 
     examplesDir / "pos" / "arrays.effekt",
+    examplesDir / "pos" / "issue319.effekt",
     examplesDir / "pos" / "maps.effekt",
 
     // bidirectional effects are not yet supported in our Chez backend
diff --git a/effekt/jvm/src/test/scala/effekt/MLTests.scala b/effekt/jvm/src/test/scala/effekt/MLTests.scala
index 1175b990b..79836dc0c 100644
--- a/effekt/jvm/src/test/scala/effekt/MLTests.scala
+++ b/effekt/jvm/src/test/scala/effekt/MLTests.scala
@@ -92,6 +92,7 @@ class MLTests extends EffektTests {
 
     // array api
     examplesDir / "pos" / "raytracer.effekt",
+    examplesDir / "pos" / "issue319.effekt",
 
     // async
     examplesDir / "pos" / "io" / "async_file_io.effekt",