Stream: beginners

Topic: Super weird bug: unrecognized name defined line above


view this post on Zulip Ian McLerran (Sep 27 2024 at 19:57):

So I just ran into a super weird bug. I get an "unrecognized name" error for a value which is defined literally the line above where It complains that the unrecongized name is. Plus, it depends on how I use it the next line down.

This compiles fine:

messages = Chat.appendUserMessage previousMessages Stdin.line!
response = Http.send (Chat.buildHttpRequest client messages {}) |> Task.result!
updatedMessages = updateMessagesFromResponse response messages |> Tools.handleToolCalls! client toolHandlerMap

This does not:

messages = Chat.appendUserMessage previousMessages Stdin.line!
updatedMessages = Http.send (Chat.buildHttpRequest client messages {})
    |> Task.result!
    |> updateMessagesFromResponse messages
    |> Tools.handleToolCalls! client toolHandlerMap

Instead I get:

── UNRECOGNIZED NAME in tools.roc ──
Nothing is named `messages` in this scope.

26│          updatedMessages = Http.send (Chat.buildHttpRequest client messages {})
                                                                       ^^^^^^^^

view this post on Zulip Ian McLerran (Sep 27 2024 at 20:02):

full source here

view this post on Zulip Anton (Sep 28 2024 at 09:14):

This could be related to ! desugaring, does it work if you replace Stdin.line! with a string?

view this post on Zulip Oskar Hahn (Sep 28 2024 at 12:45):

I get the same error when using ?

test : Result Str _
test =
    foo = "hello" |> Str.toUtf8
    bar =
        foo
            |> Str.fromUtf8?
            |> Str.concat "a"
    Ok bar

It only happens in a pipe, if ? and it is not the last function in the pipe. If you would remove the |> Str.concat "a" line, it works.

view this post on Zulip Anton (Sep 28 2024 at 12:58):

Just a note; I think ? and ! desugaring share a lot of code

view this post on Zulip Ian McLerran (Sep 28 2024 at 23:31):

I'll try to get a minimum reproduction tomorrow. For now I did check what happens if I replace the Stdin.line! with an empty string, and that still produces the same error message.


Last updated: Jul 06 2025 at 12:14 UTC