Compiler panic when scrutinizing non-`Bool` in `if ... then ... else ...`
I built Roc from source with Nix at db94b555ab1946ad6bfdb5314a11ba67d9b1d1da.
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
import pf.Stdout
import pf.Task exposing [Task]
main : Task {} _
main =
if "non bool thing here" then
Stdout.line! "True"
else
Stdout.line! "False"
$ roc build main.roc
── TYPE MISMATCH in main.roc ───────────────────────────────────────────────────
This if condition needs to be a Bool:
10│ if "non bool thing here" then
^^^^^^^^^^^^^^^^^^^^^
Right now it’s a string of type:
Str
But I need every if condition to evaluate to a Bool—either Bool.true
or Bool.false.
────────────────────────────────────────────────────────────────────────────────
thread 'main' panicked at crates/compiler/gen_llvm/src/llvm/build.rs:5764:19:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("mainForHost"), definition of value binding ValueId(4): could not find func in module ModName("UserApp") with name FuncName("#\x00\x00\x00\x00\x00\x00\x00z\x87\xceV\x11\xaaYs")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
It looks like expected behavior. Roc doesn't cast anything implicitly, so Str is an invalid type for the if predicate, which expects only Bool.
Maybe there’s another problem I missed?
The friendly human error is great, but it's followed by a compiler panic:
thread 'main' panicked at crates/compiler/gen_llvm/src/llvm/build.rs:5764:19:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("mainForHost"), definition of value binding ValueId(4): could not find func in module ModName("UserApp") with name FuncName("#\x00\x00\x00\x00\x00\x00\x00z\x87\xceV\x11\xaaYs")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
You might have missed it in the second code block; I think GitHub has it below the fold, so you have to scroll.
Thank you for the report and clarification!
Minimal repro:
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}
main = 42
similar issues:
https://github.com/roc-lang/roc/issues/5156