Stream: beginners

Topic: Crash using when


view this post on Zulip Luke Boswell (Nov 27 2022 at 00:39):

Putting this in the repl crashes Roc and I'm not sure what is causing it.

» x = 10
… when x > 1 is
…     Bool.true -> "Yes"
…     Bool.false -> "No"
"x\xe0R\x06\x01"
thread 'main' panicked at 'Roc hit an error', crates/repl_cli/src/cli_gen.rs:129:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Luke Boswell (Nov 27 2022 at 00:47):

and another

» x = 10
…
… check : Num -> Bool
… check = \x -> x > 10
…
… when check 10 is
…     Bool.true -> "Yes"
…     Bool.false -> "No"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Erroneous', crates/compiler/mono/src/ir.rs:10148:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Richard Feldman (Nov 27 2022 at 00:54):

hm, what does roc version say?

view this post on Zulip Richard Feldman (Nov 27 2022 at 00:55):

it looks like an old binary because x = 10 resulted in - which it doesn't do anymore :big_smile:

view this post on Zulip Ayaz Hafiz (Nov 27 2022 at 00:58):

matching constants in when expressions is not currently supported - you would need to use an if here, or do something like "b if b -> "Yes"" instead of the "Bool.true -> "Yes"" branch


Last updated: Jul 05 2025 at 12:14 UTC