Under Review
over 1 year ago

bug: compiler thinks all functions are background if one function in the class is annotated as such

SDK 4.1.7

import Toybox.Application;

(:background) const VER = "0.1";

(:foreground)
function set(key as PropertyKeyType, val as PropertyValueType) as Void {
    Application.Properties.setValue(key, val);
}

class Foo {
    (:foreground)
    public function onStart() as Void {
        set("v", VER);
    }
}

class Bar {
    (:background, :api3, :inline)
    function other() as Void {
        log("other backgrounnd");
    }

    (:foreground)
    public function onStart() as Void {
        set("v", VER);
    }
}

ERROR: fr255: Test.mc:25,8: Value 'set' not available in all function scopes.

As you can see Foo compiles, but Bar doesn't, because there's other() that is annotated as background.

Parents
  • If you have an instance method that is in the background context, the entire class must be put into the background context. Given how this is implemented, we cannot slice an object and have part of it in background and another part in the foreground.

    Moreover, you can request that a function be inserted into the background code section, but you cannot force the compiler to omit code from the background section. If you have a class with code you only want available to the foreground, you have to extract that code out into a separate class and not annotate it with (:background).

Comment
  • If you have an instance method that is in the background context, the entire class must be put into the background context. Given how this is implemented, we cannot slice an object and have part of it in background and another part in the foreground.

    Moreover, you can request that a function be inserted into the background code section, but you cannot force the compiler to omit code from the background section. If you have a class with code you only want available to the foreground, you have to extract that code out into a separate class and not annotate it with (:background).

Children
No Data