dart-lang / dart-lang/language
Flow analysis feature: Assignment Promotion
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
(Note: this feature request was raised in https://github.com/dart-lang/language/issues/1420 under the heading "Feature: Assignment Promotion", but since it's a flow analysis request, and that issue is tagged "field-promotion", I'm splitting the feature request out to its own separate issue).
It would be nice to allow a local variable assignment of the form id assignmentOp expression (potentially parenthesized) to act like the variable itself if used in a test. We currently allow if (x != null) ... to promote x. This change would also allow if ((x = something) != null) ... to promote x.
It only affects the left-most variable of an assignment, so if ((x = y = something) != null) ... will only promote x, not both x and y (although that's also an option if we really want it - treat both x and the assigned expression as being tested)
If you do if ((x += 1) != null) ... that still works, but there aren't that many operators which return a nullable result, so the usefulness is limited.
This is a very small feature, but it allows you to do promotion by:
int? c;
if ((c = this.capacity) != null) { ... use(c)... }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked discussion in dart-lang/language#1420 and the examples in this issue. Work out the intended promotion semantics for parenthesized assignments, chained assignments, and compound operators. Done means the language specification and any affected flow-analysis behavior have an agreed design.
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