Acknowledged
CIQQA-3054

bug: compiler uses module instead of local enum value

This code doesn't work in SDK 8.1.0:

The problem is that it thinks that Menu is WatchUi.Menu.

This causes a compilation error (at least with typecheck set to strict) because I want to assign something that is not an Action to action. This is relatively OK, though IMHO it shouldn't happen.

It also causes an unexpected behavior when running (of course it needs some changes so it compiles, or disabling typecheck):

In the switch action will never be equal to Menu (again because an Action is never equal to a module or class.

The workaround is to replace Menu with self.Menu. However I think this is a bug, and the compiler should have found the local Menu before it looks for the more remote WatchUi.Menu.

also noticed that it only happens with import Toybox.WatchUi, but not with using Toybox.WatchUi.

See also: https://forums.garmin.com/developer/connect-iq/f/discussion/407058/bug-should-a-local-enum-take-precedence-over-a-module/

  • The following bug seems to be related, as it also only occurs with "import" and not "using", although it's the inverse situation (a module prefix was specified, but the compiler acts like it wasn't):

    forums.garmin.com/.../bug-incorrect-ambigoious-error-message-even-though-correct-module-is-used

  • I think this is a fairly serious bug because if you remove "action = Menu" in the above code, it will compile without errors or warnings (at least none that are related to the use of Menu).

    This means that it's possible to write code that will silently fail, because you happened to give something in your app the same name as an imported class (e.g. Menu).

    At the very least, if Menu is interpreted as WatchUi.Menu in the case of "action = Menu", then the following line should also produce a compiler error:

    enum Action {Select, Back, Menu};

    The fact this produces no error or warning - while "action = Menu" does produce an error - seems like an inconsistency to me.