Closed filt3rek closed 1 month ago
That's how modules work. Type A
is defined in module Test
, so outside of that module, you have to either:
Test.A
.import Test;
or import Test.A;
)Context.getModule('Test')
and grab it from the returned types (particularly useful if you're trying to access a private subtype).You could also move A
to its own module in A.hx
and then simply refer to it as A
from everywhere.
Hej Juraj,
I hope you're fine and thanks for taking time to answer !
I agree if Context.getType( "A" )
didn't work at all but it does work the first time build macro context is running and just doesn't work the second time, why ?
Ok I've understood something : when using haxe.macro.Context.defineType()
with module dependency, it doesn't "place" the new type inside this module...
How can we define a new type and place it in an existing module please ?
Edit : I tried to put the module inside the pack
on the type declaration, it seems to work a half : the module of the new type is Test but Haxe mix things then and it's not working better : https://try.haxe.org/#552C2e86
How can we define a new type and place it in an existing module please ?
Context.defineModule(cl.module, [newT]);
https://try.haxe.org/#7d2C7e94
(I know, this isn't intuitive at all :sweat_smile:)
Thx Rudy ! So doing that, it won't "destroy" the yet existing types in this module right ?
We should definitely disallow defining types into existing modules for Haxe 5, if we didn't do that yet.
We should definitely disallow defining types into existing modules for Haxe 5, if we didn't do that yet.
We didn't, but that should be easy enough: https://github.com/HaxeFoundation/haxe/blob/development/src/typing/macroContext.ml#L505-L513
I use it with onAfterTyping
in order to kind of "delay" the build macro when needed.
Will Haxe 5 have something to do this ? (reorder build macros ?)
Depends what you mean exactly with reorder build macros
Sometimes I need a @:build
on a class runs after another one @:build
... Idk if it's more clear ...
That is planned, yeah (as long as it's on the same type).
Hmm I meant on 2 or more different types... Let's say a build macro on A has to collect the fields that are in another type B, but B has also a build macro that add or modify its fields.. I want build macro on B runs first because if not the build that is on A will get fields from B that will not be already added/modified ...
That will likely stay undefined build order.
But you can make sure a type is built (entirely) before another one: https://try.haxe.org/#2Afb983e
Macro.hx:5: Building,TInst(B,[])
Macro.hx:5: Building,TInst(A,[])
Macro.hx:16: Done building,TInst(A,[])
Macro.hx:16: Done building,TInst(B,[])
Thx I'll try that ;)
Hej,
I stuck with that for hours now and can't see where does it come from.
Let's say I have a
@:build( Macro.build() )
on a class. InsideMacro.build
I only get a type namedA
(which is a moduleTest
) usingContext.getType( "A" )
Then, in theContext.onAfterTyping
callback, I define a new type withContext.defineType
on which I also put@:build( Macro.build() )
. (When I define this type, I give it module dependecy of my typeA
... I don't know if it's important here but maybe, so they are both in the same module...) The first time build process runs, it reachs correctly theA
type, but the second time (for the new defined type), it throwsUncaught exception Type not found 'A'
It only works the second time, when I doContext.getType( "Test.A" )
instead of Context.getType( "A" ).Is there a reason for that please or it's a bug ?
I have a minimal example here : https://try.haxe.org/#fE9E086A
Thx for reading