roc icon indicating copy to clipboard operation
roc copied to clipboard

Import inside `expect` crashes the compiler

Open ageron opened this issue 1 year ago • 1 comments

Putting an import statement inside an expect statement causes the compiler to crash.

I'm using the latest Roc release:

$ roc version
roc nightly pre-release, built from commit faeea52 on Fri Aug 23 09:02:06 UTC 2024

Here's a minimal example bug.roc to reproduce the issue:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.14.0/dC5ceT962N_4jmoyoffVdphJ_4GlW3YMhAPyGPr-nU0.tar.br",
}

import pf.Stdout

main =
    Stdout.line! ("Hello")

expect
    import SomeMod exposing [ouch]
    ouch == "Yikes!"

With SomeMod.roc containing:

module [ouch]

ouch = "Yikes!"

A simple work-around is to move the import statement to the top of the file, but sometimes you want to make it clear that the import is only used inside the expect statement.

ageron avatar Aug 26 '24 00:08 ageron

Here's the error output:

$ roc test bug.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>
Missing module params should've been dropped by now
Location: crates/compiler/mono/src/ir.rs:4453:13

Note that the bug does not occur with roc run bug.roc, probably because the expect statement is stripped out:

$ roc run bug.roc
Hello

ageron avatar Aug 26 '24 00:08 ageron