-
-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[macro] Error when (re)defining types after failed build #11456
Comments
Ok, I just tried a simpler test case, and it worked fine. public static macro function makeThing(name:ExprOf<String>):Expr {
static var defined:Bool = false;
if(!defined) {
defined = true;
//Once per build, define the type.
Context.defineType(macro class Thing {
public var name:String;
public var value:Int = 0;
public inline function new(name:String) {
this.name = name;
}
});
}
//Multiple times per build, return the code to make a new instance.
return macro new Thing($name);
} So it seems this is allowed, but it doesn't work in a large or macro-heavy codebase. I'll see if I can find out anything more about it. |
You may want that |
In this case, the point is to call But now that you mention it, I should be doing both. I don't necessarily need |
Update: I tried it, and
This implies that Haxe clears generated types even when reusing the macro context. So in theory, you should call |
Hmm yes it's a bit more involved than that. I've updated my PR #11159 and it does seem stable on nightlies at least, what I thought was random failures were some kind of stdout race condition x_x Might be interesting to run those tests against 4.3.x too. |
Update: New question: is there a way to detect that the previous build failed? I'd rather call |
I still get this issue using json2object, I added the invalidateFiles function to the file that has the macro and it seems to fix the issue, but doesn't seem like the right way to go about it. Any updates on this issue? |
No because it's a user/lib error without minimal repro so there isn't much we can do on compiler side |
I have created a large project using Echoes, and often after a failed build, I get an error about a missing function body, pointing to this line:
Additional clues:
Context.onTypeNotFound()
call and instead useContext.defineType(def)
, the error messages tell me which type(s) are being redefined, but I'm not sure it's useful information because it causes errors in situations whereonTypeNotFound()
would lead to a successful build. I believe this is why I switched toonTypeNotFound()
in the first place.Context.onGenerate()
to exclude duplicates doesn't help; the error seems to happen before then.Printer
to printdef.fields[1]
, I always find that the function body is there, regardless of whether the build ends up succeeding or failing. So I believe the function body is being provided to the compiler, but gets deleted/lost later.I've thought of a few features that could help work around this, or at least debug it. I can compile from source to help test these, but I don't know enough to implement them.
Context.isTypeDefined()
function, so I can check if a type was preserved from the last build before callingdefineType()
. (getType()
isn't suitable because of all the side effects.)@:noCache
metadata that prevents the compile server from trying to cache the type.overwrite
argument inContext.defineType()
and/orContext.defineModule()
.The text was updated successfully, but these errors were encountered: