Complete
over 4 years ago

WERETECH-11142

Fixed

SDK4 Compiler Error: Unresolved Type

Hi,

I raised this on the forum yesterday, but the post has mysteriously disappeared.

I receive the following error when trying to build two of my more complex apps (multiple source code files and more complex jungles) - the error output from one of them is below.

I am running macos v11.2.3 (with java v1.8.0_271-b09)

VS Code 1.54.3 with Monkey C extension 0.1.10

CIQ 4.0.1

all of my apps compile/build successfully when the Monkey C Type Check Level is set to "default".  any other setting (Gradual, Informative or Strict) produces the following output.  I expect my apps to fail as I have not updated them to support the new Types scaffolding, but I wasn't expecting an error from the compiler in the manner produced.

I can provide one of my CIQ projects if required.

> Executing task in folder TrainingHR: java -Xms768m -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar /Users/rda/Library/Application Support/Garmin/ConnectIQ/Sdks/connectiq-sdk-mac-4.0.1-2021-04-21-1bb58d97e/bin/monkeybrains.jar -o bin/TrainingHR.prg -f /Users/rda/OneDrive/Home/GarminConnect/gitRepos/TrainingHR/monkey.jungle -y /Users/rda/OneDrive/Home/GarminConnect/developer_key -w -l 3 -d edge530_sim <

ERROR: Unresolved type
com.garmin.monkeybrains.compiler2.CompilerException: Unresolved type
at com.garmin.monkeybrains.compiler2.typechecker.FunctionTypeChecker.getTypeName(FunctionTypeChecker.java:431)
at com.garmin.monkeybrains.compiler2.typechecker.FunctionTypeChecker.test(FunctionTypeChecker.java:1289)
at com.garmin.monkeybrains.compiler2.typechecker.FunctionTypeChecker.testNode(FunctionTypeChecker.java:467)
at com.garmin.monkeybrains.compiler2.typechecker.FunctionTypeChecker.process(FunctionTypeChecker.java:243)
at com.garmin.monkeybrains.compiler2.TypeChecker.processFunction(TypeChecker.java:234)
at com.garmin.monkeybrains.compiler2.TypeChecker.processModule(TypeChecker.java:199)
at com.garmin.monkeybrains.compiler2.TypeChecker.processModule(TypeChecker.java:197)
at com.garmin.monkeybrains.compiler2.TypeChecker.runTypeChecker(TypeChecker.java:103)
at com.garmin.monkeybrains.ProjectBuilder.runCompiler2(ProjectBuilder.java:553)
at com.garmin.monkeybrains.Monkeybrains.runPRGCompiler(Monkeybrains.java:1542)
at com.garmin.monkeybrains.Monkeybrains.compileApplication(Monkeybrains.java:1264)
at com.garmin.monkeybrains.Monkeybrains.run(Monkeybrains.java:2672)
at com.garmin.monkeybrains.Monkeybrains.simpleMain(Monkeybrains.java:322)
at com.garmin.monkeybrains.Monkeybrains.main(Monkeybrains.java:351)
usage: monkeyc [-a <arg>] [-b <arg>] [-c <arg>] [-d <arg>] [-e]
[--Eno-invalid-symbol] [-f <arg>] [-g] [-h] [-i <arg>] [-l <arg>] [-m
<arg>] [-o <arg>] [-p <arg>] [-r] [-s <arg>] [-t] [-u <arg>] [-v] [-w]
[-x <arg>] [-y <arg>] [-z <arg>]
-a,--apidb <arg> API import file
-b,--apimir <arg> API MIR file
-c,--api-level <arg> API Level to target
-d,--device <arg> Target device
-e,--package-app Create an application package.
--Eno-invalid-symbolDo not error when a symbol is found to be invalid
-f,--jungles <arg> Jungle files
-g,--debug Print debug output
-h,--help Prints help information
-i,--import-dbg <arg> Import api.debug.xml
-l,--typecheck <arg> Type check [0=off, 1=gradual, 2=informative, 3=strict]
-m,--manifest <arg> Manifest file (deprecated)
-o,--output <arg> Output file to create
-p,--project-info <arg>projectInfo.xml file to use when compiling
-r,--release Strip debug information
-s,--sdk-version <arg> SDK version to target (deprecated, use -c
-t,--unit-test Enables compilation of unit tests
-u,--devices <arg> devices.xml file to use when compiling (deprecated)
-v,--version Prints the compiler version
-w,--warn Show compiler warnings
-x,--excludes <arg> Add annotations to the exclude list (deprecated)
-y,--private-key <arg> Private key to sign builds with
-z,--rez <arg> Resource files (deprecated)
The terminal process "java '-Xms768m', '-Dfile.encoding=UTF-8', '-Dapple.awt.UIElement=true', '-jar', '/Users/rda/Library/Application Support/Garmin/ConnectIQ/Sdks/connectiq-sdk-mac-4.0.1-2021-04-21-1bb58d97e/bin/monkeybrains.jar', '-o', 'bin/TrainingHR.prg', '-f', '/Users/rda/OneDrive/Home/GarminConnect/gitRepos/TrainingHR/monkey.jungle', '-y', '/Users/rda/OneDrive/Home/GarminConnect/developer_key', '-w', '-l', '3', '-d', 'edge530_sim'" terminated with exit code: 100.

  • I've reduced this down to the following:

    import Toybox.Lang;
    
    class MyPickerDelegate {
    
        function onCancel() as Boolean {
            return;
        }
    }
    

    While this is obviously a bug and I've filed it, the workaround here is to type your functions. In this case your class inherits from PickerDelegate, but doesn't follow the typing requirements of the base or return values of the appropriate types.

  • That makes sense. The fix should not be difficult. We will get a bug filed.

  • I've narrowed it right down to one particular function:

    The commented out RETURN statement appears to be causing the problem.  When uncommented, it causes the error, when commented compilation continues.

    (:inAppSettings)
    class StringPickerDelegate extends WatchUi.PickerDelegate {
        hidden var mPicker;
        hidden var mRetType;
        hidden var mPmax;
        hidden var mPmin;
        hidden var mFormat;
        hidden var mField;
    
        function initialize(picker, fld, pmin, pmax, retType, flFormat) {
            PickerDelegate.initialize();
            mPicker = picker;
            mField = fld;
            mPmin = pmin;
            mPmax = pmax;
            mFormat = flFormat;
            mRetType = retType;
        }
    
        function onAccept(values) {
    		var val = mPicker.getTitle(), v;
    
            if(!mPicker.isDone(values[0])) {
                mPicker.addCharacter(values[0]);
            } else {
    			v = pickerDelegateAccept(mField, mRetType, val, mFormat, mPmin, mPmax);
    			if (v) {
    	            WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
    			}
            }
        }
    
        function onCancel() {
            if (mPicker.getTitleLength() > 0) {
                mPicker.removeCharacter();
            } else {
    	        WatchUi.popView(WatchUi.SLIDE_DOWN);
            }
    //        return;
        }
    

  • ok, so the first thing I did was clone my project and remove all legacy code, watch code and all other device code, except for an Edge 530 which is the only device left in the manifest.  Compiling this produces the error still.  However, when I comment out the annotation code (to handle in app settings menu - menu2) then the compiler gets past the error and starts spitting out type checking errors (ie, what I expected to see).

    My jungles now looks like this:

    project.manifest = manifest.xml

    #edge530.excludeAnnotations = inAppSettings
    edge530.sourcePath = main/common;main/edge/source;main/edge/device/EdgeX30.mc

    edge530.resourcePath = main/edge/resources
     
    When I uncomment the inAppSettings annotation the compiler seems to get past the error.
    removing that annotation (ie, allowing inAppSettings) pulls in 7 classes across 2 .mc files.  I've done it this way to reduce the memory footprint for devices that don't support inAppSettings.
    I'll see if I can narrow this down a bit further...
  • Well this problem is happening in the compile phase, so jungles and annotations and stuff shouldn't matter at that point. They've already been processed.

    In terms of isolating the problem, the stack trace above does help a bit, but not a lot. At the time the error occurs, the compiler is processing a method of a class that is defined in the global scope. It is evaluating a return expression to verify that the value being returned matches the return type for the function, and it appears that the check has already failed (we're trying to generate an error message when the problem occurs). In order for this problem to I believe the function would need to be declared to return something other than Void.