Under Review
over 1 year ago

COMPILER BUG: cannot compile classes with static functions

There are several issues with the available compilers (SDK 4.1.7 and SDK 4.2.0 Beta 1) if a class contains a static function and the parameters of the function are Monkey Typed with the compiler set to "Gradual" or higher.

  1. Cannot find symbol errors for functions on core classes (eg. Position.Location); and
  2. Error parsing the global namespace ($.) when specifying the Monkey Type for a function parameter.

I tried the broken, replicateable code on SDK 4.1.5, SDK 4.1.6, SDK 4.1.7 and SDK 4.2.0 Beta 1.

Error #1 occurs only on SDK 4.1.7 (ie. it works fine on SDK 4.1.5, SDK 4.1.6, SDK 4.2.0 Beta 1).

Error #2 occurs on all the SDKs listed above -- SDK 4.1.5, SDK 4.1.6, SDK 4.1.7 and SDK 4.2.0 Beta 1.

These errors may or may not be related to this issue: https://forums.garmin.com/developer/connect-iq/i/bug-reports/bug-report-static-lang-dictionary-class-variable-broken-in-sdk-4-1-6

I am not able to attach my test project that will easily replicate both issues/bugs but I have emailed the ZIP to the Connect IQ team. If anyone would like the project file to validate the issue or use it as the basis for a similar sounding bug or just out of curiosity, then DM me. For reference, the function within the class looks like this:

    static function compilerErrorOne(location as Position.Location, waypoint) as BrokenClass {
        var decimalDeg = location.toDegrees();
        var wpDecDeg = waypoint.getLocation().toDegrees();
        var brokenClass = new BrokenClass(null);
        return (brokenClass);
    }
    
    static function compilerErrorTwo(location, waypoint as $.Waypoint) as BrokenClass {
        var decimalDeg = location.toDegrees();
        var wpDecDeg = waypoint.getLocation().toDegrees();
        var brokenClass = new BrokenClass(null);
        return (brokenClass);
    }

Parents
  • SDK 4.2.3 
    This may be related to this issue
    The simple code below fails to compile in SDK 4.2.3 (required for newly release devices)
    Remove the static keyword and it compiles OK. 
    No external class and only using "built-in" types.

    import Toybox.System;
    import Toybox.Lang;

    class TestCompiler {
       static function testCall(a) {
         var b = a as Array;
         System.println("Test "+b.size());
       }
    }
    Compiler failure:-
    ERROR: fr630: TestCompiler.mc:8,8: Cannot find symbol ':size' on type '$.Toybox.Lang.Array'.
Comment
  • SDK 4.2.3 
    This may be related to this issue
    The simple code below fails to compile in SDK 4.2.3 (required for newly release devices)
    Remove the static keyword and it compiles OK. 
    No external class and only using "built-in" types.

    import Toybox.System;
    import Toybox.Lang;

    class TestCompiler {
       static function testCall(a) {
         var b = a as Array;
         System.println("Test "+b.size());
       }
    }
    Compiler failure:-
    ERROR: fr630: TestCompiler.mc:8,8: Cannot find symbol ':size' on type '$.Toybox.Lang.Array'.
Children
No Data