Migration: handle code changes within a non-dead branch of an if.
The FixBuilder implemenation is now at feature parity with the
non-FixBuilder implementation when testing with api_test.dart, except
for one test of extension functionality (which doesn't seem worth
fixing right now, since extensions are still so rarely used).
Change-Id: I89df7ec388824fa9f4181706bfadbaeb232d2b5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132169
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
diff --git a/pkg/nnbd_migration/lib/src/fix_aggregator.dart b/pkg/nnbd_migration/lib/src/fix_aggregator.dart
index b746fa3..ce6dcaa 100644
--- a/pkg/nnbd_migration/lib/src/fix_aggregator.dart
+++ b/pkg/nnbd_migration/lib/src/fix_aggregator.dart
@@ -67,13 +67,13 @@
// It's not safe to eliminate the {} because it increases the scope of
// the variable declarations
} else {
- return aggregator.planner.extract(node,
- aggregator.planner.passThrough(nodeToKeep.statements.single));
+ return aggregator.planner.extract(
+ node, aggregator.innerPlanForNode(nodeToKeep.statements.single));
}
}
}
return aggregator.planner
- .extract(node, aggregator.planner.passThrough(nodeToKeep));
+ .extract(node, aggregator.innerPlanForNode(nodeToKeep));
}
@override
diff --git a/pkg/nnbd_migration/test/api_test.dart b/pkg/nnbd_migration/test/api_test.dart
index a827a77..f0c7f50 100644
--- a/pkg/nnbd_migration/test/api_test.dart
+++ b/pkg/nnbd_migration/test/api_test.dart
@@ -3923,11 +3923,6 @@
Future<void> test_named_parameter_no_default_unused_required() =>
super.test_named_parameter_no_default_unused_required();
- @override
- @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38472')
- Future<void> test_postdominating_usage_after_cfg_altered() =>
- super.test_postdominating_usage_after_cfg_altered();
-
/// Test fails under the pre-FixBuilder implementation; passes now.
@override
Future<void> test_removed_if_element_doesnt_introduce_nullability() =>
diff --git a/pkg/nnbd_migration/test/fix_aggregator_test.dart b/pkg/nnbd_migration/test/fix_aggregator_test.dart
index 38d755f..31322d7 100644
--- a/pkg/nnbd_migration/test/fix_aggregator_test.dart
+++ b/pkg/nnbd_migration/test/fix_aggregator_test.dart
@@ -39,6 +39,42 @@
expect(previewInfo.applyTo(code), 'f(a, b) => (a! + b!)!;');
}
+ Future<void> test_eliminateDeadIf_changesInKeptCode() async {
+ await analyze('''
+f(int i, int/*?*/ j) {
+ if (i != null) j.isEven;
+}
+''');
+ var previewInfo = run({
+ findNode.statement('if'): EliminateDeadIf(true),
+ findNode.simple('j.isEven'): const NullCheck()
+ });
+ expect(previewInfo.applyTo(code), '''
+f(int i, int/*?*/ j) {
+ j!.isEven;
+}
+''');
+ }
+
+ Future<void> test_eliminateDeadIf_changesInKeptCode_expandBlock() async {
+ await analyze('''
+f(int i, int/*?*/ j) {
+ if (i != null) {
+ j.isEven;
+ }
+}
+''');
+ var previewInfo = run({
+ findNode.statement('if'): EliminateDeadIf(true),
+ findNode.simple('j.isEven'): const NullCheck()
+ });
+ expect(previewInfo.applyTo(code), '''
+f(int i, int/*?*/ j) {
+ j!.isEven;
+}
+''');
+ }
+
Future<void> test_eliminateDeadIf_element_delete_drop_completely() async {
await analyze('''
List<int> f(int i) {