Acknowledged
CIQQA-3092

bug: Boolean constant can't be appended to string

class {
    (:debug) const IS_RELEASE = false;
    (:release) const IS_RELEASE = true;

    function foo() as Void {
        var s1 = "release: " + IS_RELEASE; // The operator '+' is undefined for the argument type '$.Toybox.Lang.Boolean'.
        var b = IS_RELEASE;
        var s2 = "release: " + b; // this is OK
    }
}
In the above code you can see that a constant boolean is treated differently than a variable with boolean value.
SDK 8.1.0, fr630, strict typechecker
  • This level of optimization would be nice (Prettier Monkey C does it),

  • This also suggests to me that the optimizer is unable (or unwilling) to optimize the following code by replacing b with its value:

    var b = IS_RELEASE;
    var s2 = "release: " + b;

    i.e. If the optimizer changed the above code to something like "var s2 = "release: " + IS_RELEASE;", then it seems that it would trigger the same error as the other lines, but it doesn't.

  • This only happens when optimization is enabled.

    No optimization:

    class X {
        (:debug) const IS_RELEASE = false;
        (:release) const IS_RELEASE = true;
    
        function foo() as Void {
            var s1 = "release: " + IS_RELEASE; // OK
            var b = IS_RELEASE;
            var s2 = "release: " + b; // OK
            var s3 = "true: " + true; // OK
        }
    }
    

    Optimization level 1 and higher:

    class X {
        (:debug) const IS_RELEASE = false;
        (:release) const IS_RELEASE = true;
    
        function foo() as Void {
            var s1 = "release: " + IS_RELEASE; // The operator '+' is undefined for the argument type '$.Toybox.Lang.Boolean'.
            var b = IS_RELEASE;
            var s2 = "release: " + b; // OK
            var s3 = "true: " + true; // The operator '+' is undefined for the argument type '$.Toybox.Lang.Boolean'.
        }
    }