X Tutup
Skip to content

local static vs macro expr remapping #12030

@Antriel

Description

@Antriel

Found another one. 😅
Running function expression through haxe.macro.ExprTools.map makes analyzer remove the local static variable.

function main() {
	new Foo().bar();
}

@:build(Macro.build())
class Foo {
	public function new() {}
	public function bar() {
		static var last = 0;
		if (last == 0) trace('A'); else trace('B');
		last = 1 - last;
	}
}

Module Macro.hx:

class Macro {
	public static function build() {
		var fields = haxe.macro.Context.getBuildFields();
		function identity(e) return haxe.macro.ExprTools.map(e, identity);
		for (f in fields) switch f.kind {
			case FFun(f): f.expr = identity(f.expr);
			case _:
		};
		return fields;
	}
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup