With strict type checking:
import Toybox.Application; enum Foo { Zero, One, Two, Three, } function foo(x as Foo) as Void {} function bar() as Void { foo(0); // Fails, as expected foo(Zero); // Works, as expected foo(Zero as Foo); // Works, as expected foo(0 as Foo); // Works, as expected Storage.setValue("foo", Zero); // Works Storage.setValue("foo", 0); // Works Storage.setValue("bar", Zero as Foo); // Fails (why?) Storage.setValue("baz", 0 as Foo); // Fails (why?) }
The error from Storage.setValue is "Invalid '$.Foo' passed as parameter 2 of type 'PolyType<Null or $.Toybox.Application.PropertyKeyType or $.Toybox.Lang.Array<$.Toybox.Application.PropertyValueType> or $.Toybox.Lang.Dictionary<$.Toybox.Application.PropertyKeyType,$.Toybox.Application.PropertyValueType> or $.Toybox.WatchUi.BitmapResource>'."
The first four lines of bar show that "Foo" is its own type, and that both Numbers and Foos can be passed when cast to Foo. Storage.setValue is happy to accept a Zero, so it seems like it accepts type Foo. But it *won't* accept 'Zero as Foo', or '0 as Foo'. Whats going on? It should either reject Zero (and require "Zero as Number" instead), or accept Zero, "Zero as Foo" and "0 as Foo".