Skip to content

Commit

Permalink
[tests] add test for #11545
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Feb 4, 2024
1 parent 6d96e7f commit fe3820f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/misc/projects/Issue11545/Macro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr;

class Macro {
public static function initMacro() {
Compiler.addGlobalMetadata("Main", "@:build(Macro.instrumentFields())", true, true, false);
}

static function instrumentFields():Null<Array<Field>> {
var fields:Array<Field> = Context.getBuildFields();
for (field in fields) {
switch (field.kind) {
case FFun(f):
if (f.expr == null) {
continue;
}
switch (f.expr.expr) {
case EBlock(exprs):
exprs.unshift(macro trace($v{field.name}));
case _:
}
case _:
}
}
return fields;
}
}
#end
12 changes: 12 additions & 0 deletions tests/misc/projects/Issue11545/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Main {
static function main() {
var name = new ImageName("abc");
trace(name);
}
}

abstract ImageName(String) {
public function new(name:String) {
this = name;
}
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11545/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--macro Macro.initMacro()
--run Main
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11545/compile.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Macro.hx:21: main
Macro.hx:21: _new
Main.hx:4: abc

0 comments on commit fe3820f

Please sign in to comment.