dart-lang / dart-lang/language

Statements inside if conditions

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

Description

Statements inside control statement conditions to store it, check it and also scope it inside the control statement block would be very useful.

```dart
if((Point point = parseCursorPosition(chars)) != null) {
// Do something with point
}
```
or

```dart
if(Point point = parseCursorPosition(chars); point != null) {
// Do something with point
}
```
This feature is very popular in golang world.

Right now, this is possible:

```dart
Point point;
if((point = parseCursorPosition(chars)) != null) {
// Do something with point
}
```
The only problem is this leaks the point outside its scope.

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.