The following program causes harec to abort:
type badenum = enum {
FOO, BAR,
};
export fn main() void = {
const bar = badenum::FOO: bool;
};
With this output:
$ hare run test.ha
0/4 tasks completed (0%)
harec for /home/sewn/src/test/test.ha exited with signal SIGABRT
On Sat Sep 14, 2024 at 1:06 PM EDT, sewn wrote:
> The following program causes harec to abort:
>
> type badenum = enum {
> FOO, BAR,
> };
>
> export fn main() void = {
> const bar = badenum::FOO: bool;
> };
>
> With this output:
>
> $ hare run test.ha
> 0/4 tasks completed (0%)
> harec for /home/sewn/src/test/test.ha exited with signal SIGABRT
I think casting an enum to a bool is disallowed by the language but the
compiler doesn't give an error because of a bug. Casting something like
an int to a bool is caught by the compiler and gives you an error.
Instead, you can do something like this:
type enum_type = enum {
FOO, BAR,
};
export fn main() void = {
const enum_value = enum_type::FOO;
const bar = (enum_value != enum_type::FOO);
};
That also has the added benefit of making it more clear in the code what
you're trying to do.