Stream: contributing

Topic: Panic while exhaustiveness checking `when` clauses


view this post on Zulip Sam Mohr (Apr 19 2024 at 09:46):

Hey all, I ran into this issue myself while doing library dev, and thought I could give a simpler reproduction. I've done so in this comment, with the gist below:

main =
    color = Blue
    when color is # crash assuming Red is valid
        Red -> Stdout.line "The color is red."

I propose two possible solutions, with the second being better IMO. In short, we should tell users to provide more when arms (or a _ -> arm) if we can't find enum variants during exhaustiveness checking. I'd like to pick this up if no one has any objections. I understand if the team would rather someone with more hands-on Roc compiler experience take the issue, no feelings hurt.

view this post on Zulip Sam Mohr (Apr 19 2024 at 09:48):

Also, my first try at reducing the issue in this comment isn't correct. I first considered deleting it, but I don't know the team's position on saving history. Is it better to do what I did where I leave comments at the top and bottom saying to DISREGARD, or should I just edit/delete the comment if no one is quoting it or anything?

view this post on Zulip Anton (Apr 19 2024 at 10:08):

Hi @Sam Mohr,
The second solution sounds good, you're welcome to take a crack at it :)

view this post on Zulip Anton (Apr 19 2024 at 10:08):

I first considered deleting it, but I don't know the team's position on saving history.

I have collapsed/hidden that comment.

view this post on Zulip Jeffrey Mudge (Apr 19 2024 at 13:09):

Thanks for getting a better example and for being willing to give fixing it a go! I think your solution sounds good to me and is what I would have expected to happen.

view this post on Zulip Brendan Hansknecht (Apr 19 2024 at 14:20):

I'm definitely surprised this breaks. I thought it used to work, but maybe I'm just thinking of a similar variant.

view this post on Zulip Brendan Hansknecht (Apr 19 2024 at 14:23):

As an extra note, this probably should have a chain of 2 errors. First it should say that Blue is missing. Either and explicit blue or an _ -> is needed

Once the user adds in that branch. It should error saying that Red is not a possible variant and should be removed.

I guess it could technically even give both errors at the same time.

view this post on Zulip Sam Mohr (Apr 19 2024 at 17:44):

Brendan Hansknecht said:

Once the user adds in that branch. It should error saying that Red is not a possible variant and should be removed.

This is already shown when the user adds the Blue match arm, luckily for us. If my fixing the issue causes it to show both at once, that'll be lucky. It'd probably be better to have both errors shown yes


Last updated: Jul 06 2025 at 12:14 UTC