Skip to content

Commit c1dbced

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: Test a complex example of flow analysis integration.
At this point I believe the integration between flow analysis and the migration tool is complete, so I wanted to include a more complex example at the API test level to demonstrate that it's working. The example is inspired by discussion at https://dart-review.googlesource.com/c/sdk/+/112406. Change-Id: I18152e9a07f4cd8d798cce2ae8908cb7afe6b4be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114554 Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 0c3a1a9 commit c1dbced

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/nnbd_migration/test/api_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,36 @@ class C {
976976
await _checkSingleFileChanges(content, expected);
977977
}
978978

979+
test_flow_analysis_complex() async {
980+
var content = '''
981+
int f(int x) {
982+
while (x == null) {
983+
x = g(x);
984+
}
985+
return x;
986+
}
987+
int g(int x) => x == null ? 1 : null;
988+
main() {
989+
f(null);
990+
}
991+
''';
992+
// Flow analysis can tell that the loop only exits if x is non-null, so the
993+
// return type of `f` can remain `int`, and no null check is needed.
994+
var expected = '''
995+
int f(int? x) {
996+
while (x == null) {
997+
x = g(x);
998+
}
999+
return x;
1000+
}
1001+
int? g(int? x) => x == null ? 1 : null;
1002+
main() {
1003+
f(null);
1004+
}
1005+
''';
1006+
await _checkSingleFileChanges(content, expected);
1007+
}
1008+
9791009
test_flow_analysis_simple() async {
9801010
var content = '''
9811011
int f(int x) {

0 commit comments

Comments
 (0)