Build macro cyclical redundacy

Hej :face_with_spiral_eyes:

First time I run in “cyclical reference” when building types using macros, I fight with that for 2 days now.
Error was even hard to detect since compiler doesn’t throw anything saying like “you get a partially built type”, but gives me the type without fields : Try Haxe !

class A {
	var b:B;

class B {
	var a:A;

So I suppose compiler can’t say if/when a type is fully built, I have to check if what I try to access is filled right ?

Then, I try to avoid that cyclical redundancy using Context.onAfterTyping : I try to define a new type using Context.defineType and excluding the original one, but I can’t exclude it, it tells me “Type name A is redefined from module Test” Try Haxe !
In fact doing that I just want to kind of relaunch the build macro a second time in order to this time get the missing fields of the foreign type, but I even don’t know if I’ll succed doing that.

Can anyone give me advice on how to proceed here please ? First, why the class can’t be excluded, and then globally is it a good thing to avoid cyclical redundancy ?

Thanks for reading,

I think I get it all working fine. Here’s a way (I don’t know if it’s the best one) to build types in some cases, where there are cyclical redundancies.
I share this “snippet” if it can help somebody : Snippets/ at main · filt3rek/Snippets · GitHub

1 Like