Under Review
over 2 years ago

enum with no integer and no error

enum
{
    __1 = "test",
    __2,
    __3 = 0
}

println in console:

test
0
0

but according to doc https://developer.garmin.com/connect-iq/monkey-c/functions/

Note that assigning anything other than an integer will cause an error.

  • 1. Bug is somewhere: implementation or doc

    2. I always associate enum with an integer (how to enumerate something from string)... You can use const to other types (as doc describe too).

  • It doesn't. Even with the highest level, it doesn't emit warnings of any kind.

  • I don't understand why enums need to be solely integers, we should be able to have Strings there as well. So I'm kinda happy with the bug being present.


    When you don't supply a value it defaults to 0 or whatever value came before it +1, which is documented: Enumerations are explicit or auto-incrementing constant mappings ... the symbol Monday is automatically assigned the value 0, Tuesday is assigned 1, and so on.

    enum FOO {
      boo = "Boo",
      foo,
      bar,
      baz = 500,
      jada,
    }
    
    // prints
    # Boo // boo
    # 0   // foo
    # 1   // bar
    # 500 // baz
    # 501 // jada

  • I'm not going to use type checking due to a lot of unproductive modification in source code :-)

    Yes, is connected with type but should  raise error always because keyword enum force to check type of items.

  • Yeah, I noticed this a while ago too. I think if you enable a certain level of type checking, this kind of code might produce an error. (I could be wrong.)