Under Review
over 1 year ago

Sdk 4.1.7 constant folds floats + strings incorrectly

Given this code:

        var k = 1.0;
        var x = 1.0 + "foo";
        var y = k + "foo";
        System.println(x);
        System.println(y);

The output is:

1.0foo
1.000000foo
with sdk 4.1.7, and -O1 or -O2. With -O0 (or with 4.1.5 and earlier) it prints:
1.000000foo
1.000000foo
In other words, when the addition is performed at runtime, we get 1.000000foo. When its folded at compile time, we get 1.0foo.
  • And since we always have to spell things out explicitly, my point was: just because feature X is already broken, doesn't mean that we shouldn't file a bug report when it gets broken in a different way.

    Existing apps could already be relying on the existing behavior (even if it's different in the sim vs devices, as you said.)

  • If it's been broken for 7 years, the chances of it getting fixed are between zero and nil, especially on older devices.

    As usual, you are (wilfully?) missing the point. I mean, you said it yourself -- "So a side effect of optimization" -- even if it took you a long time to figure out what was already implied in the OP.

    This bug report is not about the existing behavior of 1.0 + "foo" without optimization, it's about the fact that the same code produces different results with and without optimization. All of the other stuff in this thread is beside the point. Pretty sure optimization hasn't been around for 7 years.

    Sure, you could argue that 1.0 + "foo" is already broken and shouldn't be used, but that's also beside the point. It's also part of a larger pattern of how "X in Monkey C is broken and either shouldn't be used or requires a workaround to be used properly."

    Code that works a certain way without optimization should work the same way when optimization is turned on, period. Otherwise there's the risk of breaking existing apps when recompiled with optimization enabled.

    There's also the question of "if optimization breaks 'useless feature X', does it also break 'important feature' Y?"

  • If it's been broken for 7 years, the chances of it getting fixed are between zero and nil, especially on older devices.

  • "If it's already broken, don't fix it"

  • So a side effect of optimization, but if it's changed, what's the impact over all (other code, etc).  Does using format () (runtime) make things look good?