Ticket Created
over 2 years ago

CIQQA-1383

New type checker doesn't allow comparisons between unknown types

I'm currently validating boolean config settings by comparing the result against true. If the config is a boolean (as it should be) its a no-op, it just converts false and true to themselves. If the config contains any other type (which actually seems to happen) it converts it to false.

so basically:

var sanitized = Application.Properties.getValue("foo") == true;

and the type checker errors out

Cannot perform operation 'eq' on types 'PolyType<Null or $.Toybox.Lang.Object>' and '$.Toybox.Lang.Boolean'.

This doesn't really make sense. You can compare any two types (and the runtime supports doing so). If their types are the same, then they might compare equal. Otherwise they shouldn't. I don't want to have to check "instanceof Boolean &&" for code size reasons. Its already a shame that I can't rely on Properties having their declared types, but I've seen instances where it happens, so now I validate everything.

  • Though I'm not sure what happens in case it's null

    it sets sanitized to false...
    I already had "as Boolean" in the old compiler because I was using -l 3
    This code works as is in the old compiler at -l 3. No casting or instanceof tests required.
  • In these cases when I know what the type is (and sometimes after checking instanceof) I already had "as Boolean" in the old compiler because I was using -l 3.
    So I think this should work and should also not change the runtime code size:

    var sanitized = Application.Properties.getValue("foo") as Boolean == true;

    Though I'm not sure what happens in case it's null