Example of code which should work, but results in a type check error:
class NumberProvider { private static var data as Number?; static function get(defaultValue as Number) as Number { if (data == null) { data = defaultValue; } return data; // Error: Object of type 'PolyType<Null or $.Toybox.Lang.Number>' does not match return type '$.Toybox.Lang.Number'. } }
Yes, it is clear that NumberProvider.data is Number? in general, but at the time "return data" is executed, the type checker should realize that data is a Number.
If this code is rewritten using an intermediate local variable, the problem disappears, but that's not a desirable workaround imo.
Since the forum won't let me post the code, I'll post it as an image in a comment. Thanks, Garmin forums!