The documentation for enum says:
Enumerations are constant mappings from a
Symbol
to aNumber
value, created using theenum
keyword. Unless explicitly set, the first symbol in an enumeration is assigned a value of0
, and each subsequent symbol is automatically assigned the value of its predecessor plus one. Enumeration symbols can be used just like constants (that’s essentially what they are), and like constants, enumerations must be declared at the module or class level.Explicitly assigning a value other than an integer to an enumeration will cause an error.
So according to that, enums are always Numbers, and assigning anything else is an error. But
enum Foo { foo_boolean = false, foo_long = 42l, foo_float = 42.5, foo_double = 42.5d, foo_string = "a", foo_char = 'b', } function test() { System.println(foo_boolean); System.println(foo_long); System.println(foo_float); System.println(foo_double); System.println(foo_string); System.println(foo_char); }
compiles and runs with the expected output.
So it seems that the values are allowed to be any primitive type. I'll also note that in response to this bug report Travis.ConnectIQ wrote: "an enum can have a non-integer value", and explicitly mentions "ABC" as a possible value - suggesting that enums really are supposed to support other types.
Given all that, I suggest its the documentation that needs fixing.
Initializing an enum to null doesn't quite work though. I previously reported this bug where the compiler would crash compiling an enum that was initialized to null. The crash has been fixed, but the type checker doesn't like the resulting value:
enum Bar { bar_null = null } function test_bar() { System.println(bar_null); }
results in:
ERROR: fenix5xplus: bug.mc:6: Invalid 'Enum<$.Bar>' passed as parameter 1 of type 'PolyType<Null or $.Toybox.Lang.Object>'.
(ie its happy to accept the declaration, but complains when you try to use bar_null as a parameter to System.println). If I change it to System.println(bar_null as Number), or turn off the type checker, the code compiles, and the println outputs "null".