Skip to content

Commit 0faa3b7

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: Remove hack preventing variables showing as both nullable and non-nullable.
It's better to annotate the test to match the way the code is truly behaving, and include TODO comments indicating what needs to be changed, because then when we make the fix we'll be able to see the behavioral difference in the diff. Change-Id: I28faad5787f8c70d3b5f5d8fc3510b0e3fb294f2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109741 Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent fedd746 commit 0faa3b7

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pkg/analyzer/test/src/dart/resolution/flow_analysis_test.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,13 @@ void f(bool b, int i) {
371371
/*stmt: unreachable*/ do {} while (b);
372372
/*stmt: unreachable*/ for (;;) {}
373373
/*stmt: unreachable*/ for (var _ in []) {}
374-
/*stmt: unreachable*/ if (b) {}
375-
/*stmt: unreachable*/ switch (i) {}
374+
// TODO(paulberry): b shouldn't be considered both nullable and non-nullable.
375+
/*stmt: unreachable*/ if (/*nonNullable,nullable*/b) {}
376+
// TODO(paulberry): i shouldn't be considered both nullable and non-nullable.
377+
/*stmt: unreachable*/ switch (/*nonNullable,nullable*/i) {}
376378
/*stmt: unreachable*/ try {} finally {}
377-
/*stmt: unreachable*/ while (b) {}
379+
// TODO(paulberry): b shouldn't be considered both nullable and non-nullable.
380+
/*stmt: unreachable*/ while (/*nonNullable,nullable*/b) {}
378381
}
379382
''');
380383
}
@@ -485,15 +488,17 @@ void f() {
485488
test_logicalAnd_leftFalse() async {
486489
await trackCode(r'''
487490
void f(int x) {
488-
false && /*unreachable*/ (x == 1);
491+
// TODO(paulberry): x shouldn't be considered both nullable and non-nullable.
492+
false && /*unreachable*/ (/*nonNullable,nullable*/x == 1);
489493
}
490494
''');
491495
}
492496

493497
test_logicalOr_leftTrue() async {
494498
await trackCode(r'''
495499
void f(int x) {
496-
true || /*unreachable*/ (x == 1);
500+
// TODO(paulberry): x shouldn't be considered both nullable and non-nullable.
501+
true || /*unreachable*/ (/*nonNullable,nullable*/x == 1);
497502
}
498503
''');
499504
}
@@ -717,18 +722,10 @@ class _FlowAnalysisDataExtractor extends AstDataExtractor<Set<_FlowAssertion>> {
717722
Set<_FlowAssertion> computeNodeValue(Id id, AstNode node) {
718723
Set<_FlowAssertion> result = {};
719724
if (_flowResult.nullableNodes.contains(node)) {
720-
// We sometimes erroneously annotate a node as both nullable and
721-
// non-nullable. Ignore for now. TODO(paulberry): fix this.
722-
if (!_flowResult.nonNullableNodes.contains(node)) {
723-
result.add(_FlowAssertion.nullable);
724-
}
725+
result.add(_FlowAssertion.nullable);
725726
}
726727
if (_flowResult.nonNullableNodes.contains(node)) {
727-
// We sometimes erroneously annotate a node as both nullable and
728-
// non-nullable. Ignore for now. TODO(paulberry): fix this.
729-
if (!_flowResult.nullableNodes.contains(node)) {
730-
result.add(_FlowAssertion.nonNullable);
731-
}
728+
result.add(_FlowAssertion.nonNullable);
732729
}
733730
if (_flowResult.unreachableNodes.contains(node)) {
734731
result.add(_FlowAssertion.unreachable);

0 commit comments

Comments
 (0)