-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Usually, class functions have their typed code expressions passed through a series of expression preprocessors to ensure that we output only the language features given by Haxe that our target language provides, if our language does not provide certain features then its the job for these preprocessors to translate the incompatible feature into a new expression that our language understands. Unfortunately, this does not seam to be the case for static class variables with a default starting value, our language compiler will simply print out whatever AST that expression provides without going through our preprocessors first, this can cause unintended behavior and even errors, not good!
Heres an example, if i have a function and add this code here, even if out target language does not support the way Haxe handles blocks and the "everything is an expression" principle then our preprocessors kick in and translate the code:
var myLocalVar =
{
if (untyped name == "abcd")
5;
else if(untyped name == "efgh")
untyped brah(untyped name);
else
9 + 10;
}gets converted into:
var tempNumber
if (name == "abcd"):
tempNumber = 5
else:
if (name == "efgh"):
tempNumber = brah.call(name)
else:
tempNumber = 9 + 10
var myLocalVar: int = tempNumberhowever if we have a static variable like this:
static var myLocalVar =
{
if (untyped name == "abcd")
5;
else if(untyped name == "efgh")
untyped brah(untyped name);
else
9 + 10;
}this is the output instead:
static var myStaticVar: int = if (name == "abcd"):
5
else:
if (name == "efgh"):
brah.call(name)
else:
9 + 10^^^ In GDScript, this is invalid syntax (Expected expression for variable initial value after "=".)
reflaxe.GDScript was used for this example, but this issue is persistent in reflaxe itself. I have tested and Haxe's own transpiler does account properly for this situation.