Open davidmorgan opened 1 week ago
It looks like we currently don't support both declaring the constructor and augmenting it within the same class body. Is this blocking you?
Hmmmm. Confirmed if I split the augmentation file in two it works:
# declare_define_constructor.dart.macro_tool_output1
augment library 'package:foo/declare_define_constructor.dart';
augment class A {
external A.x();
}
# declare_define_constructor.dart.macro_tool_output2
augment library 'package:foo/declare_define_constructor.dart';
augment class A {
augment A.x();
}
but then, how is it that it works if it's a macro generating the same augmentation with clashing external+augment?
Perhaps it's to do with the output being evaluated phase by phase instead of in one shot from the file?
Whether I'm blocked / how high priority this is, is a good question :) ... I'm trying to use the CFE to test the output from the analyzer on one particular macro, I think I can reasonably work around it and focus on other things for now by putting the external
declaration in the main file, I'll try that for now.
Thanks.
Yeah, that seems to work okay--will aim to land an e2e test with that workaround tomorrow, hopefully that gets us enough scope to work on json_codable that we have plenty to do for a while :)
There seems to be a similar issue with methods but with a different symptom, approximately, the CFE can run this if it's macro output:
augment class A {
external Map<String, Object?> toJson();
augment Map<String, Object?> toJson() => {};
}
but if I supply it as a file on disk I get an error that doesn't make sense:
NoSuchMethodError: No static method 'toJson' declared in class 'F'.
Receiver: F
Tried calling: toJson()
workaround is the same, move the external
to the checked in code, e.g. here and it works fine.
Hi @johnniwinther, I'm running into what I think might be a CFE issue, could you take a look please?
What I'm trying to do is to take the code output by a new
dart_model
macro, dump it to disk, then run it with the CFE. So from the CFE's point of view they are "just" augmentations; the only weird point is that I have to explicitly add theimport augment
that the CFE would add invisibly when running as a macro.What I think I see is that the CFE-generated augmentation works but the equivalent augmentation without macros doesn't.
All the files below are in this draft PR.
So this works (with CFE build at head today):
Looking at this code in the debugger I can see the augmentations that get produced:
and then my equivalent
dart_model
macro produces something very similar, and trying to run (which means adding an explicitimport augment
) it I end up with this on disk:but running it fails:
I tried using
file
references instead of package references in this code, but it doesn't seem to make any difference.Any ideas, please?
I realize that using "external" in this way is probably not what we want in the end, so if there is some newer/better recommended way then that's good too :)
Thanks.