I think I have found a case where roc check
is unable to predict the types and just hangs...
This is my function with an error:
thisBrakesChecker : Dict a b -> Dict a b
thisBrakesChecker = \state ->
firstKVFromDict = state |> Dict.toList |> List.first
when firstKVFromDict is
Ok element ->
when state |> Dict.get element is
Ok _ -> state
Err KeyNotFound -> state
Err ListWasEmpty -> state
And here is the correct error:
➜ examples git:(main) ✗ roc check test.roc
── TYPE MISMATCH ──────────────────────────────────────────────────── test.roc ─
This 2nd argument to |> has an unexpected type:
21│ when state |> Dict.get element is
^^^^^^^
This element value is a:
(
a,
b,
)a where a implements Hash & Eq
But |> needs its 2nd argument to be:
a where a implements Hash & Eq
Note: The type variable a says it can take on any value that
implements the abilities Hash and Eq.
But, I see that the type is only ever used as a a tuple value. Can you
replace a with a more specific type?
But when I delete the type annotation then roc check
just hangs:
# thisBrakesChecker : Dict a b -> Dict a b
thisBrakesChecker = \state ->
firstKVFromDict = state |> Dict.toList |> List.first
when firstKVFromDict is
Ok element ->
when state |> Dict.get element is
Ok _ -> state
Err KeyNotFound -> state
Err ListWasEmpty -> state
Seems like to satisfy the type of this function, the key of the Dict would have to be the same type as the Dict - maybe thats why the type checker spins indefinetely.
Can you file a bug for this. Looks like a nice small repro that someone can dig into.
Created a ticket: https://github.com/roc-lang/roc/issues/6220
There was a similar issue, but not sure if it is the same bug.
I have linked those issues in the comments.
Artur Domurad has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC