Modulo operation (42 % 0
) crashes instead of panicking (divison by zero (42 / 0
) works as expected)
Not sure if a ticket has already been created
would mean that the wasm dev backend is missing the check if it is in the web repl. If it is in the local repl, it also affects the native dev backend
Locally it's
» 42 % 0
42 : Int *
which is not expected as well I think
I guess that if what the CPU instruction does when you pass in zero.... Lol
Is behavior always defined in roc? I would think there would be some constant folding pass that catches this before the ast leaves the frontend if so.
this is just a bug - we didn't implement the check :big_smile:
the only optimizations we do are related to tail-calls, mutation, and memory management
we don't yet do any inlining, constant folding, etc. - those are all left to LLVM for the moment
Filed an issue. The same for 42 // 0
btw
https://github.com/roc-lang/roc/issues/6459
@Richard Feldman I saw you closed the ticket, but the fix was only for //
, not for %
.
Tho looking at the fix for divTrunc
by Folkert, I think I can quickly replicate it for rem
So if you reopen the issue, please assign it to me, I've already started! :grinning_face_with_smiling_eyes:
Kiryl Dziamura has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC