Closed LightAndLight closed 1 year ago
I found another crash. Here's a smaller reproduction:
test.ipso
#! /usr/bin/env ipso
main : IO ()
main =
let predicate = \item -> false in
let items = ["a", "b", "c"] in
println <| debug
(array.foldl
(\{ index, result } item ->
let nextIndex = index + 1 in
case result of
Found _ ->
{ index = nextIndex, result = result}
Missing () ->
if predicate item
then { index = nextIndex, result = Found index }
else { index = nextIndex, result = result }
)
{ index = 0, result = Missing () }
items
).result
$ ./test.ipso
thread 'main' panicked at 'expected closure, got Array([Object(String("a")), Object(String("b")), Object(String("c"))])', src/lib.rs:311:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Is it just coincidence that both these involve an implementation of find
using array.foldl
?
When I change { index, result }
to acc
and use field access on acc
, the program runs correctly:
#! /usr/bin/env ipso
main : IO ()
main =
let predicate = \item -> false in
let items = ["a", "b", "c"] in
println <| debug
(array.foldl
(\acc item ->
let nextIndex = acc.index + 1 in
case acc.result of
Found _ ->
{ index = nextIndex, result = acc.result }
Missing () ->
if predicate item
then { index = nextIndex, result = Found acc.index }
else { index = nextIndex, result = acc.result }
)
{ index = 0, result = Missing () }
items
).result
https://github.com/LightAndLight/ipso/issues/326#issuecomment-1429068614: When I factor predicate
out into a top level definition, the code works correctly. I think that comment is a duplicate of https://github.com/LightAndLight/ipso/issues/357, at least.
Program:
rebase.ipso
:Output: