roc icon indicating copy to clipboard operation
roc copied to clipboard

Build crash: After type checking, lists and literals should never align in exhaustiveness checking

Open JRI98 opened this issue 8 months ago • 0 comments

The following program should not build. However, instead of displaying an error, the compiler crashes with error:

thread '<unnamed>' panicked at crates/compiler/exhaustive/src/lib.rs:480:51:
After type checking, lists and literals should never align in exhaustiveness checking
app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

main = crash ""

bug = \list ->
    when list is
        [] | [.., ..] -> list
        _ -> []

This other program has similar behavior, but the crash has a different origin:

thread '<unnamed>' panicked at crates/compiler/exhaustive/src/lib.rs:597:30:
After type checking, lists and literals should never align in exhaustiveness checking
app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br",
}

main = crash ""

bug = \list ->
    when list is
        [] | [.., ..] if Bool.true -> list
        _ -> []

After a bit of debugging, I came across this line https://github.com/roc-lang/roc/blob/6ab54c0/crates/compiler/can/src/exhaustive.rs#L446. If I change it from SP::Literal(Literal::Byte(1)) to SP::Anything, as it has been in the past, it stops crashing and instead displays an error. That said, I do not know the implications of this, so I leave it to @ayazhafiz who has made this specific change.

JRI98 avatar Jun 21 '24 18:06 JRI98