Acknowledged

bug: compilation fails because of code inside removed has block

I get a compilation error:

ERROR: fenix5: AppView.mc:38,4: Could not find method onTimerEvent on object $.AppView

I don't think I am supposed to get. SDK: 7.4.3, device: fenix5 that doesn't support ActivityRecording.Session.setTimerEventListener , and this is my relevant part of the code:

(Sorry for the unformatted code, can't post code! see: https://forums.garmin.com/developer/connect-iq/f/discussion/389914/meta-forum-returning-lots-of-errors-today-e-g-parens-links-and-images-cause-problems )

and monkey.jungle:

project.optimization = 3z
fenix5.excludeAnnotations=$(fenix5.excludeAnnotations);session_timer_event_listener
When I remove the (:session_timer_event_listener) then it compiles, but why do I need to have an empty function just to be able to compile something that can be never called?
Note that the block for the has is correctly removed ("never called is not logged"). This is my command line for compilation:
java -Xms1g -Dfile.encoding=UTF-8 -Dapple.awt.UIElement=true -jar ~/Library/Application Support/Garmin/ConnectIQ/Sdks/connectiq-sdk-mac-7.4.3-2024-12-11-90ec25e45/bin/monkeybrains.jar -o bin/App.prg -f App/monkey.jungle -y garmin/garmin_developer_key.der -d fenix5_sim -w
  • The recommendation that was given by development was to take the following block of code and put it into a separate function that can be eliminated.

    if (ActivityRecording.Session has :setTimerEventListener) {
          System.println("never called");
          session.setTimerEventListener(method(:onTimerEvent)); // error in this line
    }

  • Anyway, is there any way to do this (without Prettier Monkey C)? I tried to add an empty function with (:base) annotation, but if course that is also removed too early. So the only way to compile this is either leaving there an empty function or create two versions of the initialize , one with (:session_timer_event_listener) and one with (:no_session_timer_event_listener) (but this needs further jungling (which in my case is not a big deal as my script automatically generates either of the excludeAnnotations based on the existence of a function in debug.xml (which technically helps me doing what the 7.x compiler should already do probably with the has check in compile time) but is a bit of a hassle if someone is editing the jungle manually)

  • > - if-blocks are being removed at compile time, but too late to avoid an error about being unable to find a symbol that's called within a removed if-block

    IOW, I can imagine the following actions taking place in separate passes (in the stated order):

    A) compiler removes code based on excludeAnnotations

    B) compiler checks for functions and variables that are referenced but not defined

    C) optimizer removes if-else-branches when the value of the if-condition is known at compile time

    Maybe all that needs to happen is C needs to be moved before B)

  • I do think this bug should be fixed (thanks for posting the report) but I also wonder if the optimizer will remove unused functions?

    If so, that would be great since you wouldn't even have to manually use excludeAnnotations to get rid of your unused functions (dependent on API-based functionality) in this manner.

  • > Note that the block for the has is correctly removed ("never called is not logged")

    That doesn't prove that that the if-block for the has check was removed at compile-time, that only proves that the condition is false (either at compile-time or run-time) and the corresponding code is never run (whether that decision was made at compile-time or run-time).

    Having said that, as a test I modified your code as follows:

    //  if (ActivityRecording.Session has :setTimerEventListener) {
        if (false) {
    This modification removes any question about whether api has checks are being removed at compile-time or not. (Recall a recent forum post which found that enduro3 was not yet removing api has checks at compile time - a member of the CIQ team said that the device config needed to be updated).
    I built the resulting code with "-O 3" optimization, and I still receive the following error: Could not find method onTimerEvent on object $.TestAppView

    I can think of two possibilities:

    - if-blocks are not being removed at compile time in this case

    - if-blocks are being removed at compile time, but too late to avoid an error about being unable to find a symbol that's called within a removed if-block