I'm getting the following error:
── TYPE MISMATCH in src/RustGlue.roc ───────────────────────────────────────────
This 2nd argument to |> has an unexpected type:
86│ |> List.map generateItemGroup
^^^^^^^^^^^^^^^^^
This generateItemGroup value is a:
ItemGroup -> Str
But |> needs its 2nd argument to be:
ItemGroup -> Str
────────────────────────────────────────────────────────────────────────────────
1 error and 1 warning found in 78 ms
Is this a known bug?
Kinda,
Though if you have a small repro, it would be great to collect
I think the issue is that roc needed to the lambdaset and closure captures (which aren't displayed in the type signature, but are still pretty of the type got functions)
Thanks for your response!
I eventually found that the compiler uses the name ItemGroup
to refer to two slightly different types. This was caused by one function that was able to return a tag that wasn't included in its type annotation. I was able to find a very small repro for the latter phenomenon:
The following code type checks, and the expect test succeeds (even though it shouldn't):
module [bug]
bug : U8 -> [A]
bug = \i ->
when i is
1 -> bug 3
2 -> A
_ -> B # <- should be illegal given the annotation
expect bug 1 == B
0 failed and 1 passed in 251 ms.
Commenting out the 1
branch results in the type mismatch you'd expect to see in the previous example:
module [bug]
bug : U8 -> [A]
bug = \i ->
when i is
# 1 -> bug 3
2 -> A
_ -> B
expect bug 1 == B
── TYPE MISMATCH in Bug.roc ────────────────────────────────────────────────────
Something is off with the body of the bug definition:
3│ bug : U8 -> [A]
4│ bug = \i ->
5│> when i is
6│> # 1 -> bug 3
7│> 2 -> A
8│> _ -> B
This when expression produces:
[B, …]
But the type annotation on bug says it should be:
[…]
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 47 ms
It seems like something about the function being recursive causes the compiler to ignore the type annotation. However, changing the return type to something that's not a tag union does break as expected:
module [bug]
bug : U8 -> Str
bug = \i ->
when i is
1 -> bug 3
2 -> A
_ -> B
expect bug 1 == B
── TYPE MISMATCH in Bug.roc ────────────────────────────────────────────────────
The 2nd branch of this when does not match all the previous branches:
5│ when i is
6│ 1 -> bug 3
7│> 2 -> A
8│ _ -> B
This A tag has the type:
[A]
But all the previous branches have type:
Str
All branches of a when must have the same type!
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 46 ms
So the type annotation is not being completely ignored, but the tag union type is being silently extended.
Adding in a second type annotation seems to reintroduce the error also:
module [bug, test]
bug : U8 -> [A]
bug = \i ->
when i is
1 -> bug 3
2 -> A
_ -> B
test : U8 -> [A]
test = bug
expect bug 1 == B
── TYPE MISMATCH in Bug.roc ────────────────────────────────────────────────────
Something is off with the body of the test definition:
10│ test : U8 -> [A]
11│ test = bug
^^^
This bug value is a:
U8 -> [B, …]
But the type annotation on test says it should be:
U8 -> […]
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 55 ms
...but replacing [A]
with a type alias for [A]
suppresses it again:
module [bug, test]
OnlyA : [A]
bug : U8 -> OnlyA
bug = \i ->
when i is
1 -> bug 3
2 -> A
_ -> B
test : U8 -> OnlyA
test = bug
expect bug 1 == B
0 failed and 1 passed in 186 ms.
Safe to say I'm puzzled!
Oh wow. This is a great set of minimal repros. Can you file an issue? :folded_hands:
Sure! I'll file one tomorrow when I'm back at my laptop.
I've managed to reproduce the simply transcendental error message that led me to find this bug in the first place:
module [bug, test, wrongAnnotation]
OnlyA : [A]
bug : U8 -> OnlyA
bug = \i ->
when i is
1 -> bug 3
2 -> A
_ -> B
test : U8 -> OnlyA
test = bug
aToC : OnlyA -> [C]
aToC = \A -> C
wrongAnnotation : [C]
wrongAnnotation = aToC (bug 1)
expect bug 1 == B
── TYPE MISMATCH in Bug.roc ────────────────────────────────────────────────────
This 1st argument to aToC has an unexpected type:
19│ wrongAnnotation = aToC (bug 1)
^^^^^
This bug call produces:
OnlyA
But aToC needs its 1st argument to be:
OnlyA
────────────────────────────────────────────────────────────────────────────────
1 error and 0 warnings found in 44 ms
This feels like it might be a good hint as to what's causing this
I've added it to the issue
Last updated: Jul 06 2025 at 12:14 UTC