Skip to content
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

const extensions / constexpr in Dart #3722

Open
techvx opened this issue Apr 24, 2024 · 1 comment
Open

const extensions / constexpr in Dart #3722

techvx opened this issue Apr 24, 2024 · 1 comment
Labels
feature Proposed language feature that solves one or more problems

Comments

@techvx
Copy link

techvx commented Apr 24, 2024

Consider a case in which one may want to instantiate a given const instance, in different places, a few too times too many:

const d = Duration(milliseconds: 250); // <--
withDuration(d); // ...

After a (short) while, one may attempt to reach for a short-hand, such as:

extension DuranDurat on int {
  get Duration minutes => Duration(minutes: this);
  get Duration secs => Duration(seconds: this);
  get Duration ms => Duration(milliseconds: this);
}

This one, however - would no long evaluate at compile time.

Having a:

extension ConstDurat on int {
  const get ms => Duration(milliseconds: this);
}

Which would de-sugar into the usual:

const Duration(milliseconds: ...)

at every invocation inline, would be rather useful indeed. The C++/like constexpr were brought up already at #2222, yet I don't see much discussion around it. Low priority as it might be, it wouldn't hurt the language in the slightest.

@techvx techvx added the feature Proposed language feature that solves one or more problems label Apr 24, 2024
@mnordine
Copy link
Contributor

Dupe of #663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants