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.

  • > The error seems to come about when downcasting to a non-existent type (e.g. from Object to NavUtils.Mgrs)

    I see. In my screenshotted example, I only tried type declarations involving a non-existent type (Utils.MyTuple). In that case, I get a reasonable error: "Cannot resolve type 'Utils.MyTuple'".

    However, I modified my example to also use a cast to a non-existent type, and I still get the same error.

    // If I comment the whole Utils class out, I get the same errors
    class Utils {
        typedef MYTYUPLE as [String, String, Number, Number];
    }

    function bar(x as [String, String, Number, Number]) as Utils.MyTuple { //  Cannot resolve type 'Utils.MyTuple'.
        return x as Utils.MyTuple; // Cannot resolve type 'Utils.MyTuple'.
    }
  • Unfortunately I'm having trouble attaching the nice screenshots I prepared with code snippets.
    The error seems to come about when downcasting to a non-existent type (e.g. from Object to NavUtils.Mgrs)
  • 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.