Unexpected variable elimination when calling function with side-effects #5911

binki opened this Issue Dec 26, 2016 · 1 comment


None yet

2 participants

binki commented Dec 26, 2016

Haxe-3.4 seems to consistently emit incorrect code for this snippet on at least JavaScript and neko.

http://try.haxe.org/#93297 , using non-var function yields same: http://try.haxe.org/#c6025

class Test {
    static function main() {
        var x = 5;
        var advance = function () {
        var cur = x;

Compilation removes cur and replaces trace(cur) with trace(x) even though I call advance() which has side-effects between my assignment to cur and access or cur.

I get this JavaScript (with analyzers turned off according to try.haxe.org):

// Generated by Haxe 3.3.0
(function () { "use strict";
var Test = function() { };
Test.main = function() {
	var x = 5;
	(function() {
		x += 1;

This even shows up when running it with haxe -x Test and haxe --run Test with 3.4rc1. I’m not turning on analyzers.

@Simn Simn added the regression label Dec 26, 2016
@Simn Simn self-assigned this Dec 26, 2016
@Simn Simn added this to the 3.4 milestone Dec 26, 2016
@Simn Simn closed this in de17354 Dec 26, 2016
Simn commented Dec 26, 2016

Thanks for the very concise report, that's how I like them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment