roc
roc copied to clipboard
Nested question mark causes compiler crash
This code causes the compiler to crash with the following error on roc check or roc test.
module []
isBomb : List Str, I64, I64 -> Result Bool [OutOfBounds]
isBomb = \rows, nx, ny ->
rows
|> List.get? (Num.toU64Checked? ny)
|> Str.toUtf8
|> List.get? (Num.toU64Checked? nx)
|> Bool.isEq '*'
|> Ok
$ roc check .meta/Example.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>
a Expr::TrySuffix expression was not completely removed in desugar_value_def_suffixed
Location: crates/compiler/can/src/expr.rs:1125:40
Extracting the nested ? expressions prevents the crash:
isBomb : List Str, I64, I64 -> Result Bool [OutOfBounds]
isBomb = \rows, nx, ny ->
y = Num.toU64Checked? ny
x = Num.toU64Checked? nx
rows
|> List.get? y
|> Str.toUtf8
|> List.get? x
|> Bool.isEq '*'
|> Ok
I think the compiler panics when there's more than one ? in an expression.
It's weird because assigning then returning does work:
isBomb : List Str, I64, I64 -> Result Bool [OutOfBounds]
isBomb = \rows, nx, ny ->
result = rows
|> List.get? (Num.toU64Checked? ny)
|> Str.toUtf8
|> List.get? (Num.toU64Checked? nx)
|> Bool.isEq '*'
|> Ok
result