[macro] Build macro and type expr


I have a class “A” that contains a static function named “foo”.
In this A class a build macro is running in which I try to type the foo function. Compiler tells me that foo doesn’t exists on A, I think that’s because it hasn’t yet rendered this function.
Is there a way to get this working please ? Try Haxe !

I assume you want the haxe.macro.Type of Take a look at this Try Haxe, which constructs a ComplexType which then converts it to a Type.

In your example you used Context.typeExpr which returns a TypedExpr, I’ve always assumed this was more useful once the compiler had fully typed and processed everything, e.g for custom target generators.

And you’re correct, you can’t or shouldn’t inspect a type who’s ast is currently being built, the diagram over on the Haxe macro page is always useful to reread now and then.

Hej Skial,

Thanks for your answer.
I don’t really care about the real type of I try to type it to get the body function exprs and put them into another function.
If it’s not possible because the type that is building can’t access to all its fields, what seems logical, I just have to care to put the fields in another module.
But I wanted to be sure that it’s impossible.

You can access the function body through the field: Try Haxe !

1 Like

OMG that’s true, thx Valentin