Stream: beginners

Topic: If equality with a Str


view this post on Zulip Luke Boswell (Jul 22 2024 at 01:22):

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?

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:23):

I tried to make a minimal repro of the issue

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:36):

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.maping over the strings.

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:37):

@Brendan Hansknecht could this be related to the refcount changes?

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:41):

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]

view this post on Zulip Brendan Hansknecht (Jul 22 2024 at 01:49):

Interesting

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:54):

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.

view this post on Zulip Luke Boswell (Jul 22 2024 at 01:54):

It's for a module (and not an app) so I don't think I can --emit-llvm-ir or anything

view this post on Zulip Brendan Hansknecht (Jul 22 2024 at 01:55):

Just put it into platform switching and use the book to decide what you will print

view this post on Zulip Brendan Hansknecht (Jul 22 2024 at 01:55):

Then it will be a full app and easier to dbg in general

view this post on Zulip Luke Boswell (Jul 24 2024 at 21:38):

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.

view this post on Zulip Brendan Hansknecht (Jul 24 2024 at 21:52):

There are empty/non-printable characters in the "FOO" string that aren't displayed.

Does it contain a zwj or something?

view this post on Zulip Luke Boswell (Jul 24 2024 at 22:06):

» Str.toUtf8 "FOO"

[70, 79, 79] : List U8
» Str.toUtf8 "FOO"

[239, 187, 191, 70, 79, 79] : List U8

view this post on Zulip Luke Boswell (Jul 24 2024 at 22:06):

I'm not sure


Last updated: Jul 06 2025 at 12:14 UTC