dart-lang / dart-lang/language

Infer final fields as const for const constructors

Open
#299 26 comments 16 reactions 0 assignees View on GitHub
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

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.