haxe icon indicating copy to clipboard operation
haxe copied to clipboard

static initialisation order loop

Open romamik opened this issue 3 years ago • 1 comments

Consider following code:

// Test.hx
import Test2;

final FOO = "FOO";
final BARFOO = BAR + FOO;

function main() {
    trace('$FOOBAR $BARFOO');
}

// Test2.hx
import Test;

final BAR = "BAR";
final FOOBAR = FOO + BAR;

It will output something like "nullBAR FOOBAR" or "undefindBAR BARFOO". I believe it should either output "FOOBAR BARFOO" or give a compilation error. When running with eval it will give warning: "Warning : maybe loop in static generation". Which is great, but I think we need such warning for all platforms and I think this should be compilation error instead of warning.

https://try.haxe.org/#F6b211C6

romamik avatar Aug 31 '22 13:08 romamik

I have run into cases where the warning was emitted, even though nothing actually went wrong. It should not be a compilation error unless it is made more reliable.

Aurel300 avatar Aug 31 '22 15:08 Aurel300

This does give a warning on all targets. Please note that on try.haxe you might find it in the "Compiler output" tab. Eval is probably a special case in this regard because compiler output and run-time output are pretty much the same.

And I agree that a warning is better for this. However, now that we have a proper warning system, we could look into adding an option to turn specific warnings into errors. That's a story for another day/issue though.

Simn avatar Sep 28 '22 11:09 Simn