roc icon indicating copy to clipboard operation
roc copied to clipboard

bugs with early return followed by effectful functions

Open Giesch opened this issue 1 year ago • 4 comments

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

Giesch avatar Nov 15 '24 23:11 Giesch

This seems to be fixed on the latest nightly. Thanks Sam!

Giesch avatar Nov 22 '24 04:11 Giesch

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.

Giesch avatar Nov 30 '24 20:11 Giesch

? 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.

smores56 avatar Dec 01 '24 11:12 smores56

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

smores56 avatar Dec 05 '24 11:12 smores56