HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.2k stars 658 forks source link

haxe.macro.Printer only prints final/var based on first declaration in array #11806

Closed NQNStudios closed 1 week ago

NQNStudios commented 4 weeks ago

When an EVars ExprDef has some final vars in it, and some mutable vars in it, only the mutability of the first var will be printed by haxe.macr.Printer.

I would expect this:

new Printer().printExpr({
    expr: EVars([
        {
            name: "finalVar",
            isFinal: true
        },
        {
            name: "mutableVar",
            isFinal: false
        }
    ]),
    pos: Context.currentPos()
});

to print final finalVar; var mutableVar;. Even though this wouldn't parse back in as the original single ExprDef, this is the Haxe that will compile with the same result as the ExprDef.

I know this case is weird because raw haxe wouldn't produce the case described. You can only produce it with a macro by making an ExprDef manually.

But the problem is right here: https://github.com/HaxeFoundation/haxe/blob/760c0dd9972abadceba4e72edb1db13b2a4fb315/std/haxe/macro/Printer.hx#L255

Simn commented 1 week ago

This stems from poor data design, but changing this would break too many things for little benefit. There are probably multiple ways to setup the AST data to choke the printer, and I don't think this is worth looking into. I'll add a documentation note about this.