Acknowledged
CIQQA-3455

Linter expects a Number (only) as argument for the Dict.hasKey() method for -l1 and above

Looks like I can't post code, nor images, nor anything. So you will have to live with my description:
When retrieving a dictionary from the storage:
var foo = Toybox.Application.Storage.getValue("foo")
and using
foo.hasKey("bar")
on said dictionary, the linter expects a number only as argument and the code fails to compile.
Error message:
Invalid '$.Toybox.Lang.String' passed as parameter 1 of type '$.Toybox.Lang.Number'.
Parents
  • The compiler doesn't know which type will be returned by Application.Storage.getValue[], so it assumes it could be any of the above types. The real problem is trying to call a function [hasKey] which doesn't exist on all of those types.

    So the solution is to cast the return value of getValue to the type that you know it will be. I hate casts in Monkey C [because they're inherently unsafe), but sometimes they're unavoidable.
    [3/x]
Comment
  • The compiler doesn't know which type will be returned by Application.Storage.getValue[], so it assumes it could be any of the above types. The real problem is trying to call a function [hasKey] which doesn't exist on all of those types.

    So the solution is to cast the return value of getValue to the type that you know it will be. I hate casts in Monkey C [because they're inherently unsafe), but sometimes they're unavoidable.
    [3/x]
Children
No Data