dart-lang / dart-lang/language

assignment_to_final_local interaction with try/catch

Open
#2,860 5 comments 3 reactions 0 assignees View on GitHub
flow-analysis
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

In the following code, `x` can only be set once, but the second assignment is considered an error.

```dart
void main() {
final int x;
try {
// thow 'test';
x = 1;
} catch {
x = 2; // The final variable 'x' can only be set once.
}
print(x);
}
```

I think if the assignment is the last statement in a try block, it should not be considered to conflict with an assignment in a catch block.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Dart example and reading the language rules for final-variable assignment across try/catch control flow. Done would require a project decision on the expected behavior and corresponding language specification and test coverage; no repository files or tests are named in the issue.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.