Acknowledged
CIQQA-3561

[ERROR] PolyType cannot be cast to class Valuedef, are in unnamed module of loader 'app'

Exceptions: 1
    class com.garmin.monkeybrains.compiler2.ir.types.PolyType cannot be cast to class com.garmin.monkeybrains.compiler2.ir.namespace.Valuedef (com.garmin.monkeybrains.compiler2.ir.types.PolyType and com.garmin.monkeybrains.compiler2.ir.namespace.Valuedef are in unnamed module of loader 'app')
    
java.lang.ClassCastException: class com.garmin.monkeybrains.compiler2.ir.types.PolyType cannot be cast to class com.garmin.monkeybrains.compiler2.ir.namespace.Valuedef (com.garmin.monkeybrains.compiler2.ir.types.PolyType and com.garmin.monkeybrains.compiler2.ir.namespace.Valuedef are in unnamed module of loader 'app')
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleDefinition(ModuleVisitor.java:1647)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleStatement(ModuleVisitor.java:1726)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleStatements(ModuleVisitor.java:976)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleDefinition(ModuleVisitor.java:1672)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleStatement(ModuleVisitor.java:1726)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitModuleStatements(ModuleVisitor.java:976)
	at com.garmin.monkeybrains.compiler2.ir.visitors.ModuleVisitor.visitTopLevel(ModuleVisitor.java:1463)
	at com.garmin.monkeybrains.compiler2.SemanticAnalyzer.runSemanticAnalysis(SemanticAnalyzer.java:373)
	at com.garmin.monkeybrains.compiler2.project.ProjectBuilder.runSemanticAnalysis(ProjectBuilder.java:720)
	at com.garmin.monkeybrains.compiler2.project.ProjectBuilder.runSemanticAnalysis(ProjectBuilder.java:620)
	at com.garmin.monkeybrains.compiler2.Compiler2.build(Compiler2.java:1804)
	at com.garmin.monkeybrains.compiler2.Compiler2.buildProject(Compiler2.java:994)
	at com.garmin.monkeybrains.Monkeybrains.runCompiler2(Monkeybrains.java:1704)
	at com.garmin.monkeybrains.Monkeybrains.compileApplication(Monkeybrains.java:1674)
	at com.garmin.monkeybrains.Monkeybrains.run(Monkeybrains.java:2344)
	at com.garmin.monkeybrains.Monkeybrains.simpleMain(Monkeybrains.java:295)
	at com.garmin.monkeybrains.Monkeybrains.main(Monkeybrains.java:345)
Compiler Warnings: 1
    WARNING: vivoactive4s: The launcher icon (2000x2000) isn't compatible with the specified launcher icon size of the device 'vivoactive4s' (30x30). The image will be scaled to the target size.

For all versions of the SDK from 7.x through 8.x and all levels of typechecking I receive the above compiler error when trying to build my project.

There is no reference to a line number that might be causing this. How to debug this error further? What patterns to look for in the code base? Anyone with a similar error?

  • I wouldn't know why the compiler would crash on such a minor and easily detectable error, though.

    This is why we need the test case. We expect to generate a valid error message in all cases.

    Would you still value a log file from my side or is the above reproducible for you too?

    No, this snippet should be good enough. Thanks!

  • Type checking was also turned off, but apparently the crash occurs outside of the type checking.

    Update: I duplicated the whole barrel and started to randomly delete files to see if any caused the crash. I found the file and I found the cause. There was a duplicate name used for both a typedef and a module:

    typedef UnitName as Lang.Dictionary;
    module UnitName {
        function fun(arg) {}
    }

    After changing the name in the original, the compiler showed normal typing errors again :)

    I wouldn't know why the compiler would crash on such a minor and easily detectable error, though. 

    Thanks for your help. Would you still value a log file from my side or is the above reproducible for you too?

  • Your code is somehow generating an internal compiler error and causing the compiler to crash.

    You may be able to temporarily work around the issue by disabling type checking. Typically the easy way to do this is to make sure your VSCode environment doesn't explicitly override the typecheck level and then add the following to the jungle file for your app.

    project.typecheck = 0

    It is unlikely we will be able to reproduce your issue without a testcase of some sort. If you could add the --debug-log-level flag to the build line, that should build an archive that we can use to see what is going on here. Once you have the log file, send it to [email protected]. Please reference this post so that we can associate them on our end.

    In case it is useful, documentation for the debug flags can be found on this page. 

  • Also tested with the latest 8.3.0 and still the same issue. I am now unable to release an update for my apps. I wanted to add support for new released devices, but now I am unable to test or build the projects at all.

    Is there anyone with the same or a similar error?

    Is there any indication on where to look for the cause of this? Is this caused by specific files before compiling the code (e.g. manifest, jungle files etc.)?

    I do use a barrel in the projects. I tried to remove the barrel and in one project I received normal compiler (type) errors again after that. The error might be caused inside the barrel. I checked all changes and although there might still be type errors or logical errors in the code, I did not use any new language features or syntax that was not used already before.

    Obviously, the issue is not necessarily whether the code is incorrect or not, but how is it possible the compiler gives an error / crash without a cause and location line number.

    Any help is more than welcome! Thanks in advance.