-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Extension type new syntax available in dart Dart 3.3.0-174.2.beta, some questions and thoughts #54293
Comments
Yes, The missing piece of the implementation is that the special rules for number operator typing should not apply to the extension type operator. Normally So, for every special rules about number operation typing, it should be read as having an additional "if the invoked member is a non-extension-type member". That restriction was really always there, it was just not necessary to say so, because it couldn't not be that. Now it can. |
About the silent coercion from If we introduce implicit coercions at some point, they will likely also apply to extension types, and allowing some simple type coercions now may get in the way of doing a more general thing in the future. So not letting you do |
I conclude, speaking in very simple terms from the above that a "feature" can be implemented in some future that will allow maybe not Int When might such a thing be implemented if so? A year?, half a year? |
I'd say that if we introduce implicit coercions (which a type will have to opt into somehow), then you will be able to declare a coercion from Absolutely no guarantees that it will happen or, if it does, when. |
Thank you for your answers. Implementing the coercion (with any "but" and "opt-out") would nail it, imho. Please, if you sees it fit, you can close this issue. But by not doing it some people may have their opinion on this. And again, please you decide. |
The bug is real and should be fixed, so keeping open for that |
Ok. |
Test to verify (the already correct) CFE behavior added in https://dart-review.googlesource.com/c/sdk/+/341488 |
In response to #54293 Change-Id: Idbd898b49f631074e0cd7d3321acaeac8a89b819 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341488 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
CC @scheglov |
The specification doesn't know that extension types exist, and needs to be updated to account for them. The update is probably just that That has to be the behavior, because otherwise it's unsound. extension type Int(int i) implements int {
String operator +(int other) => "$this+$other";
}
void main() {
var x = Int(1) + 2; // Result is `String`, static type *cannot* soundly be `int`.
} See dart-lang/language#3396, which has sadly not been completed yet. Not sure "extension member" is possible, when an extension type implements |
…e invoked method is from ExtensionTypeElement. Bug: #54293 Change-Id: Ib23cfe2ff150ef34ad47b78444406d86bc4ddb0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345360 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Normally i ask on the dart official discord server. Comments in the code are describing what is happening and why something else could happen in some cases, what i see, and what in my opinion (limited knowledge) would cause the "extension type" to be perfect.
Please take note that there is here below a new type Int defined, starting from a big letter I (not "int"). Also there may be similar situations like these below, but this is enough for now.
So, do you think that at least b = b + a shouldn't be marked as error in my VScode? I imagined a reason why it should, but i don't know. Any opinions?
The text was updated successfully, but these errors were encountered: