Skip to content

Commit

Permalink
Flow analysis: Test that functionExpression_begin() preserves promoti…
Browse files Browse the repository at this point in the history
…ons of initialized vars.

While working on some other changes to flow analysis, I discovered
that this particular behaviour wasn't unit tested.

Change-Id: Ia9b27672c62177ffed80d4143f33c5b764ac7bbe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313242
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
  • Loading branch information
stereotype441 authored and Commit Queue committed Jul 16, 2023
1 parent 760c719 commit 53ead36
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,31 @@ main() {
]);
});

test('functionExpression_begin() preserves promotions of initialized vars',
() {
var x = Var('x');
var y = Var('y');
h.run([
declare(x, type: 'int?', initializer: expr('int?')),
declare(y, type: 'int?', initializer: expr('int?'), isLate: true),
x.expr.as_('int'),
y.expr.as_('int'),
checkPromoted(x, 'int'),
checkPromoted(y, 'int'),
localFunction([
// x and y remain promoted within the local function, because the
// assignment that happens implicitly as part of the initialization
// definitely happens before anything else, and hence the promotions
// are still valid whenever the local function executes.
checkPromoted(x, 'int'),
checkPromoted(y, 'int'),
]),
// x and y remain promoted after the local function too.
checkPromoted(x, 'int'),
checkPromoted(y, 'int'),
]);
});

test('functionExpression_begin() handles not-yet-seen variables', () {
var x = Var('x');
h.run([
Expand Down

0 comments on commit 53ead36

Please sign in to comment.