info has :distanceToDestination

On my new Venu X1 the datafield does not support distanceToDestination

It crashes if 'if (info has :distanceToDestination) {' is not used

ConnectIq SDK 8.4.1

  • Are you sure? Can it be that you want to check for null? 

  • during a workout the value is present on a normal datafield (so not null and exists) but not available on a connectIQ datafield

  • Installed the same datafield app on my Fenix 7X and ik works there

  • Do both a has check and a check for null. It could be null before you start recording, for example.

  •  what is the better has check? Activity.Info has :distanceToDestination or info has :distanceToDestination? IMHO the 1st is better because it enables the compiler to eliminate branches that are irrelevant for the device.

  •         //if (info has :distanceToDestination) {
                if (info.distanceToDestination != null) {
                    _remaining  = info.distanceToDestination / 1000;
                } else {
                    _remaining = 0;
                }
            //}

    I tried also with the has :, it alwais keeps 0 (on a Venu X1)
  •  It is CIQ 6.0, on the fenix it is 5.2, could it be a 6.0 bug?

  • it enables the compiler to eliminate branches that are irrelevant for the device

    Has anyone ever proven this? I think, it only worked for system 7 preview device, that had a bunch of "has..." device properties in compiler/simulator.json that were used for this optimization. I'm not aware of any real device with such configuration.

    This code

    import Toybox.Activity;
    import Toybox.System;
    
    function checkDistanceToDestination() as Void {
        if (Activity.Info has :distanceToDestination) {
            System.println("has distanceToDestination");
        } else {
            System.println("doesn't have distanceToDestination");
        }
    }

    gives the same assembler code regardless of compiler flags and devices used (actually, I've just used venu445mm and venux1 in this particular test):

    globals/checkDistanceToDestination:
        argc 1
        spush globals
        getm
        lputv 0
        getmv Toybox_Activity Info
        spush distanceToDestination
        canhazplz
        bf @_..._mc_10_4_14_4_if_else_false
        getmv Toybox_System println
        frpush
        news @strhas_distanceToDestination_1198218344
        invokem 2
        popv
        return
    _..._mc_10_4_14_4_if_else_false:
        getmv Toybox_System println
        frpush
        news @strdoesn_t_have_distanceToDestination_407115324
        invokem 2
        popv
        return
    globals/checkDistanceToDestination_func_end:

    Does anyone have a counterexample?

  • The "info" passed to compute is Activity.Info

    "info as Activity.Info"
    In a data field you might never need to call Activity.getActivityInfo() as you already see it in compute()
    You'll notice that everything in info can be "or Null" so you want to do null checks
    BTW, I ALWAYS do run-time "has" checks as the actual FW on a device can be different/newer/older that the device in the sim.
  • I see that the SDK does not have CIQ 6.0 devices yet, are the 5.2.0 devices used for compiling?