Stream: beginners

Topic: pattern matching tuple of tag unions


view this post on Zulip Kwirke (Dec 02 2023 at 16:22):

Hi, as I understand, closed tag unions can only have the values described in the tag.
If that is correct, I think this must be a bug in Roc:

» Union : [A, B]
» checkTuple : Union, Union -> Nat
… checkTuple = \a, b ->
…   when (a, b) is
…     (A, _) -> 0
…     (B, A) -> 1
…     (B, B) -> 2

── UNSAFE PATTERN ──────────────────────────────────────────────────────────────

This when does not cover all the possibilities:

 8│>        when (a, b) is
 9│>          (A, _) -> 0
10│>          (B, A) -> 1
11│>          (B, B) -> 2

Other possibilities include:

    ( B, _ )

view this post on Zulip Ayaz Hafiz (Dec 02 2023 at 16:29):

Yeah, this is a bug. Thanks for the report! Do you mind making a github issue?

view this post on Zulip Kwirke (Dec 02 2023 at 16:37):

Thank you! I'll open one now.


Last updated: Jul 06 2025 at 12:14 UTC