Open jtiai opened 3 years ago
As I mentioned in the realtime chat this is not due to the bool
, it seems to be a dot operators with type mismatch bug.
This code shouldnt compile either, since you're passing an int as a bool and Nim doesnt implictly convert.
You can do the following and it'll work fine for you.
{.experimental: "dotOperators".}
type
Flag = enum
A
Flags = set[Flag]
template `.=`*(flags: Flags, key: Flag, val: int | bool) =
if val.bool: flags.incl key else: flags.excl key
var flags: Flags
flags.A = 123
The following code doesn't compile and causes unhandled exception:
Example
Current Output
Expected Output
Compiler provides meanful error message or compiles.
Possible Solution
If
flags.A = 123
is written asflags.A = bool(123)
code compiles as expected.