Acknowledged
CIQQA-3090

bug: Symbol Not Found Error when using module level variables without MyModule. prefix

SDK 8.1.0, simulator fr955 (it doesn't mean it work on real device, it just means I haven't tried it)

module MyModule {
    var foo as Number = 0;

    function bar() as Void {
        foo = foo + 1;
    }
}

MyModule.bar();

Error: Symbol Not Found Error

Details: Failed invoking <symbol>

Stack:

Encountered app crash.

It crashes so hard it's not even able to produce the stack trace!

See from 2016: https://forums.garmin.com/developer/connect-iq/f/discussion/4287/symbol-not-found-error-when-using-module-level-variables/

  • I realize this is just a code fragment, but the line "MyModule.bar()" isn't valid at the global scope (it's a syntax error). You can't just call a function at the global scope unless you're using it as an initializer [*]. To be fair, this style of code fragment is often used in the SDK docs, so....

    e.g. [*]

    module MyModule {
        var foo as Number = 0;

        function bar() as Boolean {
            foo = foo + 1;
            return true;
        }
    }

    //  at global scope
    var x = MyModule.bar(); // this doesn't crash for me (in the sim for fr955)

    Nonetheless, I also tried something that's perhaps closer to your intent and it still didn't crash for me (in the sim for fr955):

    import Toybox.Application;
    import Toybox.Lang;
    import Toybox.WatchUi;
    
    module MyModule {
        var foo as Number = 0;
    
        function bar() as Boolean {
            foo = foo + 1;
            return true;
        }
    }
    
    class TestTapDFApp extends Application.AppBase {
    
        function initialize() {
            AppBase.initialize();
            MyModule.bar();
            //...
        }
        //...
    }
    

    I built with the default optimization level and without any external optimizer like monkey c prettier.

    Do you have a more complete code sample / recreation procedure?

    Hopefully I'm not missing something.