Stream: beginners

Topic: code generation fail on recursion


view this post on Zulip Gabriel Pickl (Dec 06 2022 at 21:51):

I am still having a lot of trouble getting code to compile that contains recursion, which is tough when trying to write a recursive parser.
this snippet:

parse = \input, accumulator ->
        when itemsParser input is
            Parsed newItem rest ->
                when delimiterParser rest is
                    Parsed _ rest2 ->
                        parse rest2 (List.append accumulator newItem)
                    ParseFailed _ ->
                        Parsed (List.append accumulator newItem) rest
            ParseFailed _ ->
                Parsed accumulator input

    @Parser \input ->
        parse input []

Fails with the cryptic error message

thread 'main' panicked at 'Symbol `20.IdentId(74)` is not defined in environment {`20.IdentId(85)`: ValueId(1), `20.IdentId(135)`: ValueId(4)}', crates/compiler/alias_analysis/src/lib.rs:664:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

When running build (not when running check though)

view this post on Zulip Gabriel Pickl (Dec 06 2022 at 21:54):

lifting the parse function to toplevel seems to have fixed it

view this post on Zulip Ayaz Hafiz (Dec 06 2022 at 22:15):

Could you file a GitHub issue with the program that fails?

If you are able to minimize it that would be helpful, but no pressure to - even providing the whole file will be helpful.

view this post on Zulip Gabriel Pickl (Dec 06 2022 at 23:47):

I unfortunately only committed the working version, but i'll try to reproduce it later. Right now I'm glad I'm finally done with my parser excursion. also found a very weird bug where roc would just jumble my lists when reversed them twice, but that's also not easy to isolate

view this post on Zulip Ayaz Hafiz (Dec 06 2022 at 23:48):

No worries! I am generally aware of this recursive bug and we're working on fixing it. If you see the list bug again we'd love to get an issue for that too.

view this post on Zulip Nick Hallstrom (Feb 13 2023 at 06:31):

Think I'm running into this now and I have a simple example that reproduces it:

app "echo"
    packages { pf: "cli-platform/main.roc" }
    imports [pf.Stdin, pf.Task.{ Task }]
    provides [main] to pf

main : Task {} []
main = test

test : Task {} []
test =
    a <- Task.await Stdin.line
    if a == "done" then Task.succeed {} else test

This gives me the error:

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread '<unnamed>' panicked at 'no lambda set found for (`20.IdentId(27)`, [
    InLayout(
        21,
    ),
    InLayout(
        33,
    ),
]): LambdaSet {
    set: [
        ( 20.27, [InLayout(21), InLayout(23)]),
        ( 20.32, [InLayout(1)]),
    ],
    args: [
        InLayout(
            1,
        ),
    ],
    ret: InLayout(
        1,
    ),
    representation: InLayout(
        24,
    ),
    full_layout: InLayout(
        25,
    ),
}', crates/compiler/mono/src/layout.rs:1500:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Last updated: Jul 05 2025 at 12:14 UTC