Skip to content

Commit e5e8f84

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Rework how final and late are represented in flow analysis tests.
The fields `isFinal` and `isLate` are moved to the `Var` class. This should allow greater flexibility when experimenting with possible changes in promotion behavior for final and late variables. Bug: dart-lang/language#1721 Change-Id: I3a328566b4a55244ca76c41da6e362066118d283 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217261 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 95dc8bd commit e5e8f84

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,9 @@ main() {
13021302

13031303
test('initialize() does not promote when final', () {
13041304
var h = Harness();
1305-
var x = Var('x', 'int?');
1305+
var x = Var('x', 'int?', isFinal: true);
13061306
h.run([
1307-
declareInitialized(x, expr('int'), isFinal: true),
1307+
declareInitialized(x, expr('int')),
13081308
checkNotPromoted(x),
13091309
]);
13101310
});
@@ -1326,9 +1326,9 @@ main() {
13261326
var h = Harness()
13271327
..addSubtype('T&int', 'T', true)
13281328
..addFactor('T', 'T&int', 'T');
1329-
var x = Var('x', 'T', isImplicitlyTyped: true);
1329+
var x = Var('x', 'T', isFinal: true, isImplicitlyTyped: true);
13301330
h.run([
1331-
declareInitialized(x, expr('T&int'), isFinal: true),
1331+
declareInitialized(x, expr('T&int')),
13321332
checkPromoted(x, 'T&int'),
13331333
]);
13341334
});
@@ -1348,9 +1348,9 @@ main() {
13481348

13491349
test('when final', () {
13501350
var h = Harness();
1351-
var x = Var('x', 'T');
1351+
var x = Var('x', 'T', isFinal: true);
13521352
h.run([
1353-
declareInitialized(x, expr('T&int'), isFinal: true),
1353+
declareInitialized(x, expr('T&int')),
13541354
checkNotPromoted(x),
13551355
]);
13561356
});
@@ -1370,9 +1370,9 @@ main() {
13701370

13711371
test('when final', () {
13721372
var h = Harness();
1373-
var x = Var('x', 'dynamic', isImplicitlyTyped: true);
1373+
var x = Var('x', 'dynamic', isFinal: true, isImplicitlyTyped: true);
13741374
h.run([
1375-
declareInitialized(x, expr('Null'), isFinal: true),
1375+
declareInitialized(x, expr('Null')),
13761376
checkNotPromoted(x),
13771377
]);
13781378
});
@@ -1398,10 +1398,10 @@ main() {
13981398

13991399
test('initialize() does not store expressionInfo when late', () {
14001400
var h = Harness();
1401-
var x = Var('x', 'Object');
1401+
var x = Var('x', 'Object', isLate: true);
14021402
var y = Var('y', 'int?');
14031403
h.run([
1404-
declareInitialized(x, y.expr.eq(nullLiteral), isLate: true),
1404+
declareInitialized(x, y.expr.eq(nullLiteral)),
14051405
getSsaNodes((nodes) {
14061406
expect(nodes[x]!.expressionInfo, isNull);
14071407
}),

pkg/_fe_analyzer_shared/test/mini_ast.dart

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ Statement checkUnassigned(Var variable, bool expectedUnassignedState) =>
5555

5656
Statement continue_() => new _Continue();
5757

58-
Statement declare(Var variable,
59-
{required bool initialized,
60-
bool isFinal = false,
61-
bool isLate = false}) =>
62-
new _Declare(variable, initialized ? expr(variable.type.type) : null,
63-
isFinal, isLate);
58+
Statement declare(Var variable, {required bool initialized}) =>
59+
new _Declare(variable, initialized ? expr(variable.type.type) : null);
6460

65-
Statement declareInitialized(Var variable, Expression initializer,
66-
{bool isFinal = false, bool isLate = false}) =>
67-
new _Declare(variable, initializer, isFinal, isLate);
61+
Statement declareInitialized(Var variable, Expression initializer) =>
62+
new _Declare(variable, initializer);
6863

6964
Statement do_(List<Statement> body, Expression condition) =>
7065
_Do(block(body), condition);
@@ -664,9 +659,14 @@ abstract class TryStatement extends Statement implements TryBuilder {
664659
class Var {
665660
final String name;
666661
final Type type;
662+
final bool isFinal;
667663
final bool isImplicitlyTyped;
664+
final bool isLate;
668665

669-
Var(this.name, String typeStr, {this.isImplicitlyTyped = false})
666+
Var(this.name, String typeStr,
667+
{this.isFinal = false,
668+
this.isImplicitlyTyped = false,
669+
this.isLate = false})
670670
: type = Type(typeStr);
671671

672672
/// Creates an L-value representing a reference to this variable.
@@ -948,16 +948,13 @@ class _Continue extends Statement {
948948
class _Declare extends Statement {
949949
final Var variable;
950950
final Expression? initializer;
951-
final bool isFinal;
952-
final bool isLate;
953951

954-
_Declare(this.variable, this.initializer, this.isFinal, this.isLate)
955-
: super._();
952+
_Declare(this.variable, this.initializer) : super._();
956953

957954
@override
958955
String toString() {
959-
var latePart = isLate ? 'late ' : '';
960-
var finalPart = isFinal ? 'final ' : '';
956+
var latePart = variable.isLate ? 'late ' : '';
957+
var finalPart = variable.isFinal ? 'final ' : '';
961958
var initializerPart = initializer != null ? ' = $initializer' : '';
962959
return '$latePart$finalPart$variable${initializerPart};';
963960
}
@@ -972,9 +969,11 @@ class _Declare extends Statement {
972969
h._irBuilder.atom(variable.name);
973970
h._typeAnalyzer.analyzeVariableDeclaration(
974971
this, variable.type, variable, initializer,
975-
isFinal: isFinal, isLate: isLate);
972+
isFinal: variable.isFinal, isLate: variable.isLate);
976973
h._irBuilder.apply(
977-
['declare', if (isLate) 'late', if (isFinal) 'final'].join('_'), 2);
974+
['declare', if (variable.isLate) 'late', if (variable.isFinal) 'final']
975+
.join('_'),
976+
2);
978977
}
979978
}
980979

0 commit comments

Comments
 (0)