I found this issue and thought this was strange behaviour.
https://github.com/roc-lang/roc/issues/6919
Basically it doesn't seem to match on the first string, but it does on the others.
Am I missing something obvious here?
I tried to make a minimal repro of the issue
It's like there is something funny going on with memory, like something is writing over the Str
. Or maybe this is related to the List Str
somehow, as I'm List.map
ing over the strings.
@Brendan Hansknecht could this be related to the refcount changes?
Yeah, I think it's related to having a List of refcounted things.
Here's an even smaller repro
module []
fromStr : Str -> _
fromStr = \raw ->
if raw == "FOO" then FOO
else if raw == "BAR" then BAR
else if raw == "BAZ" then BAZ
else OTHER
expect
actual = ["FOO", "BAR","BAZ"] |> List.map fromStr
expected = [FOO, BAR, BAZ]
actual == expected
actual = [OTHER, BAR, BAZ]
expected = [FOO, BAR, BAZ]
Interesting
I'm trying to debug this further... is there any way I can dump the IR at any of the stages in the compiler?
I've tried things like this $ ROC_CHECK_MONO_IR=1 ./target/debug/roc test Broken.roc
.
It's for a module (and not an app) so I don't think I can --emit-llvm-ir
or anything
Just put it into platform switching and use the book to decide what you will print
Then it will be a full app and easier to dbg in general
Big thank you to @Basile Henry who I think found the underlying issue here. There are empty/non-printable characters in the "FOO" string that aren't displayed. I'll raise an idea thread to see if there is a way we can help others in future avoid this issue.
There are empty/non-printable characters in the "FOO" string that aren't displayed.
Does it contain a zwj or something?
» Str.toUtf8 "FOO"
[70, 79, 79] : List U8
» Str.toUtf8 "FOO"
[239, 187, 191, 70, 79, 79] : List U8
I'm not sure
Last updated: Jul 06 2025 at 12:14 UTC