-
Notifications
You must be signed in to change notification settings - Fork 213
Constant from extension method? #663
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
Comments
It is definitely pretty far away from the constants that we support today: Extension methods can never be part of a constant expression evaluation (that would enable constant evaluation to run arbitrary code), and the only non-operator member that we can evaluate in a constant is We have many requests for more powerful constant evaluation, but it is a very delicate area (there is no end to the complexities popping up when we consider constant evaluation together with Granted—it looks nice! But there are lots of reasons why it won't be easy to make it happen.. (OK, here's a loophole: if we consider a compilation process where |
That "loophole" would be equivalent to having "potentially constant methods", methods which are acceptable in constant expressions because they only depend on class C {
final int x;
const C(this.x);
const int next => x + 1;
} Then That's a rather large increase in complexity and expressive power for const expressions, and we have no current plans to do add any new major features to constant expressions. |
Cf. dart-lang/sdk#29277, https://github.com/dart-lang/sdk/issues/20962 as well. Maybe |
I thought extensions where basically a syntax sugar kind of feature based on macro.
|
Sorry for commenting on such an old issue, but is this feature being considered at the time? |
No. There is no current work being done on allowing potentially constant functions. |
Any way something like this could work?
as long as
this
is itselfconst
?The text was updated successfully, but these errors were encountered: