-
-
Notifications
You must be signed in to change notification settings - Fork 694
Open
Description
The analyzer optimizer fails to fold a constant conditional expression inside an abstract type when StringBuf is used in the same function. The condition this == 0 where this is known to be 0 at compile-time should be evaluated to true, but instead generates a runtime conditional 0 == 0 ? 65 : 66.
Removing the new StringBuf().addChar(10); line causes the analyzer to correctly optimize the conditional.
Minimal Reproduction
abstract W(Int) from Int {
public inline function test() {
trace(this == 0 ? 65 : 66);
new StringBuf().addChar(10);
}
}
class Test {
static function main() {
final w:W = 0;
w.test();
}
}Actual Output (JS)
class Test {
static main() {
console.log("Test.hx:3:", 0 == 0 ? 65 : 66); // Not optimized!
let _this_b = "";
_this_b += String.fromCodePoint(10);
}
}Expected Output (JS)
class Test {
static main() {
console.log("Test.hx:3:", 65); // Should be constant-folded
let _this_b = "";
_this_b += String.fromCodePoint(10);
}
}Notes
- Removing
new StringBuf().addChar(10);causes the analyzer to correctly optimize to65 - The same code outside an abstract is optimized correctly
- The value of w is known at compile-time
(w:W = 0)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels