dart-lang / dart-lang/language

Flow analysis feature: Assignment Promotion

Open
#1,844 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature flow-analysis
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.