-
Notifications
You must be signed in to change notification settings - Fork 196
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
Augmenting declarations cannot occur outside parts, right? #3647
Comments
@jakemac53, @munificent, do you agree? |
This is the current spec yes - but there have been discussions about allowing them anywhere so it could change. |
I agree that that's what's specified. You can have an empty "main" library file with a single "augment import "real_library.dart";` declaration, then declare all your stuff in that library augmentation file, and have both your main declarations and augmentation declarations in the same file. If you can do that, we might as well allow declaring augmentations in the main library file too. You can argue that you shouldn't need to have declarations and augmentations on top of those declarations in the same library, but I'm not absolutely certain there aren't things you can do with Maybe someone just likes to do: class Pomegranate {
// all the base stuff
}
// All the Iterable stuff here.
augment class Pomegranate with Iterable<Seed> {
Iterator<Seed> get iterator => ...
}
// All the comparable stuff here.
augment class Pomegranate implements Comparable<Pomegranate> {
int compareTo(Pomegranate other) => weight.compareTo(other.weight);
static int compare(Pomegranate p1, Pomegranate p2) => p1.compareTo(p2);
} Who are we to disallow that (or force them to have an extra spurious file to achieve it), if there is no technical reason for it. </soapbox> |
So every library can contain |
I'd recommend allowing augmentations in a library as well as in a library augmentation, but each augmenting declaration should apply to an original declaration in the same library. (This is in line with the rule that every augmentation should apply to the original declaration, or to an augmenting declaration which occurs in the parent chain of library augmentations, or in the main library. That is, "you can only augment your parents, which includes yourself". ;-) @dart-lang/language-team, WDYT? |
SGTM, I think this is in line with the recent in person discussions on this. It does make me sad that you can't augment a declaration produced by a macro, given that macro augmentations always come last, but I don't see a reasonable way around that. |
Agree. If macro introspection can only see entire, fully augmented declarations, there is no way we can also have augmentations that occur after macros. |
I believe this is implemented in #3848 |
[Update: At this time, May 2024, there are no library augmentation files. We will use parts to do this job. Changed the title accordingly.]
Thanks to @sgrekhov for bringing up this topic. I might have missed it, but I do not think the augmentation library specification specifies that
That is, a library that contains a
library augment ...
directive can haveaugment
declarations, others can't.The text was updated successfully, but these errors were encountered: