Odd compiler errors with SDK 7.4.1

I'm aware of the previous export problem with SDK 7.4.0, and while my issue below may be a duplicate of this post but I wanted to start a new thread with a more appropriate thread subject/title.

I was compiling and running locally (in the sim) one of my apps just fine with SDK 7.3.1, however when I downloaded SDK 7.4.1 the unchanged code was reporting 6 new errors.

Two of the errors were "Statement is not reachable" errors, which I easily tracked down to functions not marked as potentially returning Null.

The other errors, however, are very strange and are contained with the onTap() function of an InputDelegate.

var coords = clickEvent.getCoordinates();
for (var i=1; i <= 12; i++) {
  // do whatever
  var drawable = _view.findDrawableById("someID");
  if ( != null) {
    // do stuff
    break;
  }
}
The above code generates two errors:
  • Trying to access an uninitialized variable.
  • Cannot perform operation 'add' on types 'Uninitialized' and '$.Toybox.Lang.Number'.

I've isolated this down to the i++ portion of the for-loop and don't see how I can possibly work around this. I have tried changing it to a while-loop, moving the code location, changed variable names, defined the counter/index outside of the loop, changed the way the addition is done, etc but the end result is always the same errors.

Top Replies

All Replies

  • In the meantime, you can let the team know that it seems to have something to do with conditionals without matching else statements.  From the places I've seen problems, it is in places with conditional logic.

    I'm not sure this is the case; at least, not for me. Although one of my error locations matches that hypothesis, I tried putting else statements on everything in the function but it did not have any effect.

     I've emailed the logs (at intermediate level) to the Connect IQ team.

  • , here are simple and reproducible examples of errors in 7.4.1, that build and work fine in 7.3.1:


    import Toybox.Lang;

    // Build with "-l 3"
    function f1(x as Number or Float) as Float {
        if ((x instanceof Number && x > 0) || (x instanceof Float && x > 1)) {
            return 0.0;
        } else if (x instanceof Number) { // Statement is not reachable
            return x.toFloat();
        } else {
            return x; // Object of type 'PolyType<$.Toybox.Lang.Float or $.Toybox.Lang.Number>' does not match return type '$.Toybox.Lang.Float'.
        }
    }

    import Toybox.Lang;
    
    // Build with "-l 3"
    function f2(x as Number, y as Number?) as Number? {
        return x != null ? y : null; // Object of type 'PolyType<Any or Null or $.Toybox.Lang.Number>' does not match return type 'PolyType<Null or $.Toybox.Lang.Number>'.
    }
    

    import Toybox.Lang;

    // Build with "-l 3"
    function f3(x as Number?, y as Number?) as Boolean {
        if ((x != null && y == null|| (x == null && y != null)) {
            var z = x != null;

            return z; // Object of type 'Any' does not match return type '$.Toybox.Lang.Boolean'.
        } else {
            return false;
        }
    }

    Can't format code properly due to "Sorry, you have been blocked. You are unable to access forums.garmin.com".
  • It's a zip file, you can see what's inside and decide if you want to send it or not. The verbose includes your source code IMHO

  • The intermediate logs include the generated .mir file while the verbose logs also include the *.mc files.

  • Logs do help. We use what you send in, but may not always reply back. dbrobert sent in some logs already and we were able to fix a compiler bug that his code revealed. If you want to send in logs we can verify that the issue you are seeing is fixed as well.

  • If anyone is still under NDA with Garmin (I think I am but would have to check), perhaps those of us with larger codebase apps (I have three pretty big apps) could be used as SDK beta testers? Just an idea to run by Nick K and whomever else might need to approve it?

  • We use what you send in, but may not always reply back

     as long as it is actually helpful.  I just sent the email.  I know it's afternoon on Friday -- can you just help make sure it reaches the right people?  

    It took me a while for some reason to get the logs the right way.  It turned out that I had to use the -d flag to compile for a specific device.

    For forum searchers in the future, here's a full command on Mac that creates logs in a useful format:

    /usr/bin/java -Xms1g -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar "/Users/myUserName/Library/Application Support/Garmin/ConnectIQ/Sdks/connectiq-sdk-mac-7.4.1-2024-11-27-9fadc2337/bin/monkeybrains.jar" -o "/path/to/the/project/dist/file_name.iq" -f "/path/to/the/project/monkey.jungle;/path/to/the/project/barrels.jungle" -y "/Users/myUserName/Code/Garmin/Setup/developer_key" --debug-log-level 2 --debug-log-output log_output_file.zip -r -O 3 -d fenix7x_sim

  • You can also just add the debug arguments/parameters to the "Compiler Options" config for the Monkey C extension within VS Code. That's how I did it. The key though is to remember to remove it when you're done.

  • Got them and they're passed on.

  • we were able to fix a compiler bug that his code revealed

    Sweet! Will we see SDK 7.4.2 soon then?