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.
  • Yes... thats what I've been saying all along. From the original post: In other words, when the addition is performed at runtime, we get 1.000000foo. When its folded at compile time, we get 1.0foo

  • How things are dealt with in println() and drawText() has been there for a long time.  Do you see it if you use toString() or format()?

    Maybe they did something in optimization that made the issue more visible, but I've seen similar issues for a long time..

  • It's is connected probably due to optimizing - counting value during compile, so now on prg happy you have “1.0foo“ literal without any additional counting. So compiler as external tool runs different like ciq but should the same.

  • You don't seem to get it. This is a bug in the compiler. Yes, there are workarounds, and yes, it's probably not a great idea to use this feature in the first place. But there being alternatives doesn't mean its not a bug.

  • No, it hasn't been this way for a long time. This was introduced in compiler 2 (ie 4.1.6), and only happens at -O1 or -O2.

    That's the point. The *runtime* is consistent. But the new compiler is incorrectly optimizing at compile time.