Stream: beginners

Topic: Workaround for "An internal compiler expectation was broken"


view this post on Zulip Niklas Konstenius (Oct 13 2024 at 19:49):

I'm working on a simple JSON parser in Roc but have run into a compiler bug:

$ roc --version
roc nightly pre-release, built from commit 5646f829dcd on Sat Oct 12 09:13:49 UTC 2024


$ roc run  examples/simple1.roc
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>
I thought a non-nullable-unwrapped variant for a lambda set was impossible: how could such a lambda set be created without a base case?
Location: crates/compiler/mono/src/layout.rs:1705:61

I have no clue what is triggering this bug so I'm kind of stuck now.
Any ideas what I can do to workaround the bug?
Should I report it?

The source of my project can be found here: https://github.com/konnik/roc-json-parser

Any help appreciated.

view this post on Zulip Sam Mohr (Oct 13 2024 at 21:15):

@Niklas Konstenius Richard is working on the lambda sets code right now, there's a good chance that this is fixed by that. Until then, there's not a great way around it besides trying to reshape your API "until it works"

view this post on Zulip Brendan Hansknecht (Oct 13 2024 at 22:32):

Tends to happen with very recursive functions often with dynamic captures (like parser combinators), but I don't have a good solution. My best advice is comment out code until it works and then try writing code that doesn't work in different ways. Also, if you have functions that return functions, it sometimes can help to wrap that whole thing in another function:
Instead of:

myFunc = funcGenerator 123

It would be:

myFunc = \x -> (funcGenerator 123) x

view this post on Zulip Brendan Hansknecht (Oct 13 2024 at 22:33):

But yeah, this is probably the sharpest edge of the type system and compiler lowering right now. Hopefully richards coming fixes will remove the error all together, but no idea how long that will take to land

view this post on Zulip Brendan Hansknecht (Oct 13 2024 at 22:33):

Oh, also, make sure your code passes roc check .... Sometimes that catches the real issue

view this post on Zulip Niklas Konstenius (Oct 14 2024 at 06:05):

Thanks for the info. The code is a classic recursive descend parser using combinators so it's seems it pretty likely to trigger this bug then.

I wrote the hole parser in one go using only roc check so I have really no clue which of the lines triggered the bug. I will try your rewrite suggestions and do some general cleanup and hopefully this will make it work. Otherwise I'll just wait for Richard to save us. :smile:


Last updated: Jul 06 2025 at 12:14 UTC