bugs with early return followed by effectful functions
When working on roc-ray examples, I ran into what looks like a couple of bugs with try and ? early returns with effectful functions. It seems like the backpassing-style continuation that gets generated is required to be pure. When using ? this makes multiple early returns from fallible effectful functions into a compile error. When using try, roc check passes but roc build crashes.
These are two minimal-ish repros in roc-ray examples. They can be run with:
just dev examples/early-return-question-mark.roc
just dev examples/early-return-try.roc
This seems to be fixed on the latest nightly. Thanks Sam!
I'm noticing now that this works only with the try keyword but not with the ? suffix. If ? is supposed to continue being supported, then this is still an issue.
? will continue to be supported, but not in its current form. Currently, func? arg1 arg2 is desugared to Result.try (func arg1 arg2) \ok -> ..., which means it's calling a pure function always. Without effect polymorphism, this style of desugaring won't work with purity inference. Therefore, we will need to replace its impl with the try impl, which is an early return on failure.
I've now used a proper type-checking impl that I made for try to implement ? in https://github.com/roc-lang/roc/pull/7309, so this should be fixed once that's merged in a bit