Stream: compiler development

Topic: List destructure syntax


view this post on Zulip JRI98 (Jul 09 2025 at 21:41):

Hi there. Love the progress on the new compiler :ok:
I decided to check it on some old code. After a couple of modifications to modernize it, I reached the following snippet (reduced from a larger file):

module [last]

last = |l|
    match l {
        [] -> Err(EmptyList)
        [.., e] -> Ok(e)
    }

I'm wondering if the syntax is correct but I managed to craft an example that crashes the compiler :stuck_out_tongue_closed_eyes:

[1]    89899 segmentation fault  ./zig-out/bin/roc check main.roc

view this post on Zulip Luke Boswell (Jul 09 2025 at 21:45):

Match uses => now.

Shouldn't segfault though :thinking:

view this post on Zulip JRI98 (Jul 09 2025 at 21:49):

Still segfaults with => but what I was looking for was the right syntax. Thank you

view this post on Zulip JRI98 (Jul 09 2025 at 21:49):

In fact I could have just looked through the new snapshots (which are great btw). But at least the segfault gets reported

view this post on Zulip JRI98 (Jul 09 2025 at 21:55):

Hmmm don't know if it might help with debugging, but if I invert the order of the branches it works:

module [last]

last = |l|
    match l {
        [.., e] => Ok(e)
        [] => Err(EmptyList)
    }

view this post on Zulip JRI98 (Jul 09 2025 at 21:57):

This works too:

module [last]

last = |l|
    match l {
        _ => Err(EmptyList)
        [.., e] => Ok(e)
    }

Seems to happen when an empty list is the first branch.

view this post on Zulip Luke Boswell (Jul 09 2025 at 21:58):

That's a cool bug.

view this post on Zulip Richard Feldman (Jul 09 2025 at 22:19):

thanks for reporting this! I'm working on a fix.

view this post on Zulip Richard Feldman (Jul 09 2025 at 22:45):

fix: https://github.com/roc-lang/roc/pull/7986

view this post on Zulip JRI98 (Jul 09 2025 at 23:14):

Actually it doesn't seem to be fixed :thinking:
(leaving the example here again)

module [last]

last = |l|
    match l {
        [] => Err(EmptyList)
        [.., e] => Ok(e)
    }

view this post on Zulip Luke Boswell (Jul 09 2025 at 23:33):

It looks related to nested patterns specifically

view this post on Zulip Luke Boswell (Jul 09 2025 at 23:34):

It's fine with either just a lambda or just a match, but both tother and we are re-using the same scratch for patterns (my current theory)

view this post on Zulip Brendan Hansknecht (Jul 09 2025 at 23:38):

This is why we need to clean up all the low hanging fuzzer crashes. Then it can reach more meaningful failures like this

view this post on Zulip Luke Boswell (Jul 09 2025 at 23:44):

Apparently our segfault is in the type-checker ... specifically with empty lists

view this post on Zulip Luke Boswell (Jul 10 2025 at 00:21):

Ok, I've got a fix... I'll push it up soon.

view this post on Zulip Luke Boswell (Jul 10 2025 at 01:06):

https://github.com/roc-lang/roc/pull/7988


Last updated: Jul 26 2025 at 12:14 UTC