Skip to content

Commit

Permalink
Flow analysis: promote to "types of interest" on assignment.
Browse files Browse the repository at this point in the history
This allows so-called "ensure guarded" promotions, e.g.
- `if (x is! int) x = 0;`
- `if (x == null) x = 0;`
- `x ??= 0;`

The latter two are particularly important to prepare for NNBD.

Change-Id: Ib53ca916e6d485945326b19e86f8cfb5b3ee2160
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123280
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Oct 29, 2019
1 parent d213d3c commit 780af0f
Show file tree
Hide file tree
Showing 11 changed files with 831 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FlowAnalysisHelper {
if (flow == null) return null;

if (node.operator.type == TokenType.QUESTION_QUESTION_EQ) {
flow.ifNullExpression_rightBegin();
flow.ifNullExpression_rightBegin(node.leftHandSide);
}

var left = node.leftHandSide;
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3130,7 +3130,7 @@ class ResolverVisitor extends ScopedVisitor {
}

if (operator == TokenType.QUESTION_QUESTION) {
flow?.ifNullExpression_rightBegin();
flow?.ifNullExpression_rightBegin(node.leftOperand);
right.accept(this);
flow?.ifNullExpression_end();
} else {
Expand Down
572 changes: 382 additions & 190 deletions pkg/front_end/lib/src/fasta/flow_analysis/flow_analysis.dart

Large diffs are not rendered by default.

Loading

0 comments on commit 780af0f

Please sign in to comment.