Stream: compiler development

Topic: return in when branch


view this post on Zulip Anton (Jan 24 2025 at 12:46):

Do we no longer support return in when branches?

── MISSING EXPRESSION in ./examples/DesugaringTry/main.roc ─────────────────────

I am partway through parsing a when expression, but I got stuck here:

21│      when Str.split_first(str, " was born in ") is
22│          Err(err1) -> return Err(err)
                          ^

I was expecting to see an expression like 42 or "hello".

view this post on Zulip Anthony Bullard (Jan 24 2025 at 14:48):

That is definitely a bug

view this post on Zulip Anthony Bullard (Jan 24 2025 at 14:49):

But that's interesting, it's in the parser

view this post on Zulip Anton (Jan 24 2025 at 14:53):

It was fixed when I moved the return to the next line

view this post on Zulip Anton (Jan 24 2025 at 14:53):

I think I vaguely remember @Joshua Warner and @Sam Mohr talking about a parser change related to indentation with return?

view this post on Zulip Anton (Jan 24 2025 at 14:56):

I made #7545 for this

view this post on Zulip Anthony Bullard (Jan 24 2025 at 14:59):

I'll try to take that on once we get the release out

view this post on Zulip Anthony Bullard (Jan 24 2025 at 14:59):

Or at least once I'm down updating tutorial/homepage

view this post on Zulip Sam Mohr (Jan 24 2025 at 16:08):

We never did support it in the first place

view this post on Zulip Sam Mohr (Jan 24 2025 at 16:08):

But we should add support yes

view this post on Zulip Anton (Jan 24 2025 at 16:25):

Sam Mohr said:

We never did support it in the first place

It does work :p (as long as it's not all on the same line)

view this post on Zulip Sam Mohr (Jan 24 2025 at 16:26):

Yeah exactly

view this post on Zulip Sam Mohr (Jan 24 2025 at 16:26):

Many people have been confused by it

view this post on Zulip Joshua Warner (Jan 24 2025 at 16:28):

Should be a fairly straight forward change: moving return from being parsed only as a stmt to being an expr (same place if is parsed)


Last updated: Jul 06 2025 at 12:14 UTC