roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.16k stars 293 forks source link

Calling a Module function which depends on an Effectful module param inside Task.loop causes compiler panic #7116

Open imclerran opened 4 days ago

imclerran commented 4 days ago

Error message:

thread 'main' panicked at crates/compiler/mono/src/borrow.rs:396:34:
internal error: entered unreachable code: 
        No borrow signature for LambdaName { name: `35.IdentId(0)`, niche: Niche(Captures([])) } layout.

        Tip 1: This can happen when you call a function with less arguments than it expects.
        Like `Arg.list!` instead of `Arg.list! {}`.

                            Tip 2: `roc check yourfile.roc` can sometimes give you a helpful error. 

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Minimum reproduction:

app [main] {
    cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
}

import Module { task: (Task.ok {}) }

main = Task.loop! {} loop

loop = \{} -> Task.ok (Step  Module.effect!)
module { task } -> [effect]

effect = task
imclerran commented 4 days ago

One additional finding: inlining the loop function eliminates the panic.

So the following will not cause the bug:

main = Task.loop! {} \{} -> Task.ok (Step Module.effect!)
imclerran commented 4 days ago

Linking to Zulip