Stream: beginners

Topic: Compiler thinks when does not cover all the possibilities


view this post on Zulip Ilya Shmygol (Apr 30 2025 at 16:15):

Hi! Me again. I sense gradual typing problem again, but am struggling to understand it and to find a better solution. Could you please explain me why the folliwing code:

is_within : BoundedInterval _, BoundedInterval _ -> Bool
is_within = |inner_interval, outer_interval|
    when (normalized(inner_interval), normalized(outer_interval)) is
        (_, Err(IntervalWasEmpty)) ->
            Bool.false

        (Err(IntervalWasEmpty), _) ->
            Bool.true

        (Ok((inner_first, inner_last)), Ok((outer_first, outer_last))) ->
            inner_first >= outer_first and inner_last <= outer_last

Fails with the error:

── UNSAFE PATTERN in ./src/Interval.roc ────────────────────────────────────────

This when does not cover all the possibilities:

306│>      when (normalized(inner_interval), normalized(outer_interval)) is
307│>          (_, Err(IntervalWasEmpty)) ->
308│>              Bool.false
309│>
310│>          (Err(IntervalWasEmpty), _) ->
311│>              Bool.true
312│>
313│>          (Ok((inner_first, inner_last)), Ok((outer_first, outer_last))) ->
314│>              inner_first >= outer_first and inner_last <= outer_last

Other possibilities include:

    ( Ok _, Err _ )
    ( Ok _, Ok _ )

I would have to crash if I saw one of those! Add branches for them!

Even though I clearly covered these possibilities.

Here is definition of the normalized function:

normalized : BoundedInterval a -> Result (Int a, Int a) [IntervalWasEmpty]

view this post on Zulip Anton (Apr 30 2025 at 16:24):

This is indeed a bug with tuples #5530

view this post on Zulip Ilya Shmygol (Apr 30 2025 at 16:26):

Oh, ok. Thanks for the info.


Last updated: Jul 06 2025 at 12:14 UTC