dart-lang / dart-lang/language
Infer final fields as const for const constructors
Open
enhanced-const
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
:wave: Here's a language feature request (should it be moved to https://github.com/dart-lang/language?)
Consider the following const classes:
```dart
class Bar {
const Bar();
}
class Foo {
const Foo();
final Bar bar = const Bar();
}
```
This proposal is to allow the following:
```dart
const foo = Foo();
const bar = foo.bar;
```
Currently, it is impossible to assign `foo.bar` to a `const` variable and triggers a
> Const variables must be initialized with a constant value.
Contributor guide
Assessment
This issue has not been assessed yet.