dart-lang / dart-lang/language

Allow referring to assigned variable within its initializer.

Open
#542 8 comments 4 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Cascade syntax helps avoid redundant references to the same variable, but it breaks down once you need to reference that variable within a cascade call.

The following are logically equivalent:
```dart
var foo = bar();
foo.baz();
```

```dart
var foo = bar()
..baz();
```

However the same equivalence can't be made with:

```dart
var foo = bar();
foo.baz(() {
foo.blub();
});
```

```dart
var foo = bar()
..baz(() {
foo.blub(); // Error, "Local variable 'foo' can't be referenced before it is declared"
});
```

Contributor guide

Open the contributing guide

Research direction

Start with the issue's cascade and initializer examples and read the discussion for the intended language semantics. Determine whether closures inside an initializer may refer to the variable being declared, including the required diagnostic or specification behavior; done means the proposal has an agreed, precise resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.