Bypass getter inside getter
Closed this issue · 4 comments
class Main {
static var inst(get, null):String;
public static function main() {
trace(inst);
}
static function get_inst() {
if(inst == null) inst = 'foo';
return inst;
}
}
genes generated:
static get inst() {
return this.get_inst()
}
static get_inst() {
if (Main.inst == null) {
Main.inst = "foo";
};
return Main.inst;
}
which overflows because of the mutual recursion
Perhaps genes should generate a real underlying variable, e.g.:
static get inst() {
return this.get_inst()
}
static get_inst() {
if (Main.__genes__inst == null) {
Main.__genes__inst = "foo";
};
return Main.__genes__inst;
}
Oh, that's interesting. I thought this case was only possible with @:isVar, where the native getter would not be generated. Maybe it's different for static properties, I'll have a look.
iirc @:isVar
is only useful for (get/never, set/never)
because null
accessor means the var can be accessed within the class, so there would be a physical var.
I only generate the native setters/getters for improved interop with js. But as far as generation of code goes I'd like to stay close to what haxe does as maybe some day I can rip out the ExprEmitter for JSGenApi expr/value (which for me depends on HaxeFoundation/haxe#8625)