Under Review

Type checker issues with aliased tuple type

I have my own tuple type defined as:

typedef MGRS as [String, String, Number, Number];

However, I am encountering a lot of pain trying to use it elsewhere in my code because the type checker does not seem to recognize it properly.

When using it as a return type, I get the error:

Object of type '$.NavUtils.Mgrs' does not match return type '$.NavUtils.Mgrs'.

When indexing my tuple, I get the warning:

Cannot determine if container access is using container type.

When using it to define a callback type, I get the error:

Cannot assign value '$.Toybox.Lang.Method(mgrs as $.NavUtils.Mgrs) as Void' to member ':_callback'.

Where _callback is typed exactly as Method(mgrs as $.NavUtils.Mgrs) as Void


The only workaround seems to be to disable the type checker.

  • Interesting - I kinda discounted the typo right off the bat bc I thought it was too simple of an explanation and I would've expected a different, more helpful, error message in that case.

    e.g.

    For one thing, the following error that you actually encountered looks nonsensical on its face (regardless of what might or might not be wrong with your code):
    > Object of type '$.NavUtils.Mgrs' does not match return type '$.NavUtils.Mgrs'.
    Do you have a more detailed snippet that reproduces this problem (or can you describe a few more things about it)?
  • I'm on SDK 7.4.3 type check level 3 as well if that helps.

  • Hmm as Flocsy sardonically pointed out (there are nicer ways to ask for more code), this is EBCAK. Since I usually like to rely on the compiler to steer me in the right direction though, I would still like to see it identify the real error when I refer to non-existent types.

  • This bug report looks interesting, but I agree that more code might be necessary for anyone else to reproduce your problem.

    I compiled the following snippet (at the global scope) without any warnings or errors at type check level 3, with SDK 7.4.3 and 8.0.0-beta..

    https://pastebin.com/KR6W0X35