dart-lang / dart-lang/language

Constant from extension method?

Open
#663 6 comments 8 reactions 0 assignees View on GitHub
enhanced-const feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Any way something like this could work?

```dart
extension Time on int {
Duration get ms =>
Duration(microseconds: (this * Duration.microsecondsPerMillisecond).toInt());
}

main() {
// const time = Duration(milliseconds: 250);
const time = 250.ms;
print(time);
}
```

as long as `this` is itself `const`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.