Flow analysis: Test that functionExpression_begin() preserves promotions 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 <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Paul Berry 2023-07-16 13:11:17 +00:00 committed by Commit Queue
parent 760c719b97
commit 53ead360bb

View file

@ -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([