diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t02.dart b/TypeSystem/flow-analysis/reachability_for_A01_t02.dart index 18d9752a1f..8c0a049d59 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t02.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t02.dart @@ -16,10 +16,14 @@ /// `C` is a definite assignment. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1() { int i; - for (; (i = 42) < 0;) { - } + for (; (i = 42) < 0;) {} i; // Definitely assigned. } @@ -28,7 +32,7 @@ test2() { [ for (; (i = 42) < 0;) 0 ]; - i; // Definitely assigned. + i; } test3() { @@ -36,11 +40,86 @@ test3() { { for (; (i = 42) < 0;) 0: 0 }; - i; // Definitely assigned. + i; +} + +test4() { + int i; + for (; ((i,) = (42,)) == 0;) {} + i; +} + +test5() { + int i; + for (; ((x: i) = (x: 42)) == 0;) {} + i; +} + +test6() { + int i; + for (; (C(v: i) = C(42)) == 0;) {} + i; +} + +test7() { + int i; + [ + for (; ((i,) = (42,)) == 0;) 0 + ]; + i; +} + +test8() { + int i; + [ + for (; ((x: i) = (x: 42)) == 0;) 0 + ]; + i; +} + +test9() { + int i; + [ + for (; (C(v: i) = C(42)) == 0;) 0 + ]; + i; +} + +test10() { + int i; + { + for (; ((i,) = (42,)) == 0;) 0: 0 + }; + i; +} + +test11() { + int i; + { + for (; ((x: i) = (x: 42)) == 0;) 0: 0 + }; + i; +} + +test12() { + int i; + { + for (; (C(v: i) = C(42)) == 0;) 0: 0 + }; + i; } main() { test1(); test2(); test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + test11(); + test12(); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t03.dart b/TypeSystem/flow-analysis/reachability_for_A01_t03.dart index 770b152c40..db233fb879 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t03.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t03.dart @@ -16,6 +16,11 @@ /// `before(C)`. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1() { int n; for (n = 42; n > 0;) { // n definitely assigned @@ -39,8 +44,86 @@ test3() { }; } +test4() { + int n; + for ((n,) = (42,); n > 0;) { + break; + } +} + +test5() { + int n; + for ((x: n) = (x: 42); n > 0;) { + break; + } +} + +test6() { + int n; + for (C(v: n) = C(42); n > 0;) { + break; + } +} + +test7() { + int n; + [ + for ((n,) = (42,); n < 0;) + 0 + ]; +} + +test8() { + int n; + [ + for ((x: n) = (x: 42); n < 0;) + 0 + ]; +} + +test9() { + int n; + [ + for (C(v: n) = C(42); n < 0;) + 0 + ]; +} + +test10() { + int n; + { + for ((n,) = (42,); n < 0;) + 0: 0 + }; +} + +test11() { + int n; + { + for ((x: n) = (x: 42); n < 0;) + 0: 0 + }; +} + +test12() { + int n; + { + for (C(v: n) = C(42); n < 0;) + 0: 0 + }; +} + main() { test1(); test2(); test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + test11(); + test12(); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t04.dart b/TypeSystem/flow-analysis/reachability_for_A01_t04.dart index f0d5a3ae43..5acf2623ac 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t04.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t04.dart @@ -15,6 +15,11 @@ /// that `assignedIn(U)` is detected by flow analysis. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1() { late int n; for ( @@ -63,8 +68,59 @@ test3() { }; } +test4() { + late int n; + for ( + ; + () { + if (1 > 2) { + n; // possibly assigned + } + return true; + }(); + (n,) = (42,) + ) {} +} + +test5() { + late int n; + [ + for ( + ; + () { + if (1 > 2) { + n; + } + return true; + }(); + (x: n) = (x: 42) + ) + 0, + ]; +} + +test6() { + late int n; + { + for ( + ; + () { + if (1 > 2) { + n; + } + return true; + }(); + C(v: n) = C(42) + ) + 0: 0, + }; +} + main() { print(test1); print(test2); print(test3); + print(test4); + print(test5); + print(test6); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t05.dart b/TypeSystem/flow-analysis/reachability_for_A01_t05.dart index 2a29d35299..d95a104727 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t05.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t05.dart @@ -15,6 +15,11 @@ /// that `assignedIn(S)` is detected by flow analysis. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1() { late int n; for ( @@ -78,9 +83,77 @@ test4() { }; } +test5() { + late int n; + for ( + ; + () { + if (1 > 2) { + n; // possibly assigned + } + return true; + }(); + ) { + (n,) = (42,); + } +} + +test6() { + late int n; + [ + for ( + ; + () { + if (1 > 2) { + n; + } + return true; + }(); + ) + (x: n) = (x: 42), + ]; +} + +test7() { + late int n; + { + for ( + ; + () { + if (1 > 2) { + n; + } + return true; + }(); + ) + (C(v: n) = C(42)): 0, + }; +} + +test8() { + late int n; + { + for ( + ; + () { + if (1 > 2) { + n; + } + return true; + }(); + ) + 0: (C(v: n) = C(42)), + }; +} + + main() { print(test1); print(test2); print(test3); print(test4); + print(test5); + print(test6); + print(test7); + print(test8); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t09.dart b/TypeSystem/flow-analysis/reachability_for_A01_t09.dart index 408bda1b2c..c485b5b072 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t09.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t09.dart @@ -16,12 +16,15 @@ /// `before(C)` as well. /// @author sgrekhov22@gmail.com -int? x = (2 > 1) ? 1 : null; +class C { + int v; + C(this.v); +} test1(int? n) { if (n != null) { // n promoted to `int` - for (() {n = x;}; n > 0;) { // n demoted to `int?` -// ^ + for (() {n = 42;}; n > 0;) { // n demoted to `int?` +// ^ // [analyzer] unspecified // [cfe] unspecified } @@ -31,8 +34,8 @@ test1(int? n) { test2(int? n) { if (n != null) { [ - for (() {n = x;}; n > 0;) 0 -// ^ + for (() {n = 42;}; n > 0;) 0 +// ^ // [analyzer] unspecified // [cfe] unspecified ]; @@ -42,8 +45,40 @@ test2(int? n) { test3(int? n) { if (n != null) { { - for (() {n = x;}; n > 0;) 0: 0 -// ^ + for (() {n = 42;}; n > 0;) 0: 0 +// ^ +// [analyzer] unspecified +// [cfe] unspecified + }; + } +} + +test4(int? n) { + if (n != null) { // n promoted to `int` + for (() {(n,) = (42,);}; n > 0;) { // n demoted to `int?` +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +test5(int? n) { + if (n != null) { + [ + for (() {(x: n) = (x: 42);}; n > 0;) 0 +// ^ +// [analyzer] unspecified +// [cfe] unspecified + ]; + } +} + +test6(int? n) { + if (n != null) { + { + for (() {C(v: n) = C(42);}; n > 0;) 0: 0 +// ^ // [analyzer] unspecified // [cfe] unspecified }; @@ -54,4 +89,7 @@ main() { print(test1); print(test2); print(test3); + print(test4); + print(test5); + print(test6); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t10.dart b/TypeSystem/flow-analysis/reachability_for_A01_t10.dart index b1e4ed26c4..a2f35d0c6d 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t10.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t10.dart @@ -15,6 +15,11 @@ /// that `capturedIn(C)` is detected by flow analysis. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1(int? n) { if (n != null) { // n promoted to `int` @@ -26,9 +31,9 @@ test1(int? n) { }(); ) {} n.isEven; - // ^^^^^^ - // [analyzer] unspecified - // [cfe] unspecified +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified } } @@ -44,9 +49,9 @@ test2(int? n) { ) 0, n.isEven, - // ^^^^^^ - // [analyzer] unspecified - // [cfe] unspecified +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified ]; } } @@ -63,9 +68,9 @@ test3(int? n) { ) 0: 0, n.isEven: 0, - // ^^^^^^ - // [analyzer] unspecified - // [cfe] unspecified +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified }; } } @@ -82,9 +87,64 @@ test4(int? n) { ) 0: 0, 0: n.isEven, - // ^^^^^^ - // [analyzer] unspecified - // [cfe] unspecified +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + }; + } +} + +test5(int? n) { + if (n != null) { + // n promoted to `int` + for ( + ; + () { + late (int?,) i = ((n,) = (42,)); + return false; + }(); + ) {} + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test6(int? n) { + if (n != null) { + [ + for ( + ; + () { + late ({int? x}) i = ((x: n) = (x: 42)); + return false; + }(); + ) + 0, + n.isEven, +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + ]; + } +} + +test7(int? n) { + if (n != null) { + { + for ( + ; + () { + late C? i = (C(v: n) = C(42)); + return false; + }(); + ) + 0: 0, + n.isEven: 0, +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified }; } } @@ -94,4 +154,7 @@ main() { print(test2); print(test3); print(test4); + print(test5); + print(test6); + print(test7); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t11.dart b/TypeSystem/flow-analysis/reachability_for_A01_t11.dart index 7ffe902e2a..e9a18fa654 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t11.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t11.dart @@ -15,6 +15,11 @@ /// that `capturedIn(U)` is detected by flow analysis. /// @author sgrekhov22@gmail.com +class C { + int v; + C(this.v); +} + test1(int? n) { if (n != null) { // n promoted to `int` for (; n > 0; () {n = 42;}) { // n demoted to `int?` @@ -47,8 +52,43 @@ test3(int? n) { } } +test4(int? n) { + if (n != null) { // n promoted to `int` + for (; n > 0; () {(n,) = (42,);}) { +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +test5(int? n) { + if (n != null) { + [ + for (; n > 0; () {(x: n) = (x: 42);}) 0 +// ^ +// [analyzer] unspecified +// [cfe] unspecified + ]; + } +} + +test6(int? n) { + if (n != null) { + { + for (; n > 0; () {C(v: n) = C(42);}) 0: 0 +// ^ +// [analyzer] unspecified +// [cfe] unspecified + }; + } +} + main() { print(test1); print(test2); print(test3); + print(test4); + print(test5); + print(test6); } diff --git a/TypeSystem/flow-analysis/reachability_for_A01_t12.dart b/TypeSystem/flow-analysis/reachability_for_A01_t12.dart index 46f5fd66bd..cf95a65281 100644 --- a/TypeSystem/flow-analysis/reachability_for_A01_t12.dart +++ b/TypeSystem/flow-analysis/reachability_for_A01_t12.dart @@ -15,7 +15,10 @@ /// that `capturedIn(S)` is detected by flow analysis. /// @author sgrekhov22@gmail.com -int? x = (2 > 1) ? 1 : null; +class C { + int v; + C(this.v); +} test1(int? n) { if (n != null) { // n promoted to `int` @@ -23,7 +26,7 @@ test1(int? n) { // ^ // [analyzer] unspecified // [cfe] unspecified - late int? v = (n = x); // n demoted to `int?` + late int? v = (n = 42); // n demoted to `int?` } } } @@ -36,7 +39,7 @@ test2(int? n) { // [analyzer] unspecified // [cfe] unspecified () { - late int? v = (n = x); + late int? v = (n = 42); } ]; } @@ -49,7 +52,7 @@ test3(int? n) { // ^ // [analyzer] unspecified // [cfe] unspecified - () {late int? v = (n = x);}: 0 + () {late int? v = (n = 42);}: 0 }; } } @@ -61,7 +64,44 @@ test4(int? n) { // ^ // [analyzer] unspecified // [cfe] unspecified - 0: () {late int? v = (n = x);} + 0: () {late int? v = (n = 42);} + }; + } +} + +test5(int? n) { + if (n != null) { // n promoted to `int` + for (;n > 0 ;) { +// ^ +// [analyzer] unspecified +// [cfe] unspecified + late (int,) v = ((n,) = (42,)); + } + } +} + +test6(int? n) { + if (n != null) { + [ + for (;n > 0 ;) +// ^ +// [analyzer] unspecified +// [cfe] unspecified + () { + late ({int x}) v = ((x: n) = (x: 42)); + } + ]; + } +} + +test7(int? n) { + if (n != null) { + { + for (; n > 0;) +// ^ +// [analyzer] unspecified +// [cfe] unspecified + () {late C? v = (C(v: n) = C(42));}: 0 }; } } @@ -71,4 +111,7 @@ main() { print(test2); print(test3); print(test4); + print(test5); + print(test6); + print(test7); } diff --git a/TypeSystem/flow-analysis/reachability_for_A02_t02.dart b/TypeSystem/flow-analysis/reachability_for_A02_t02.dart index 521fa66eaa..ea43257b40 100644 --- a/TypeSystem/flow-analysis/reachability_for_A02_t02.dart +++ b/TypeSystem/flow-analysis/reachability_for_A02_t02.dart @@ -14,7 +14,12 @@ /// `true` literal then assignment in `S` is a definite assignment. /// @author sgrekhov22@gmail.com -main() { +class C { + int v; + C(this.v); +} + +test1() { int i; for (; true;) { i = 42; @@ -22,3 +27,34 @@ main() { } i; // Definitely assigned. } + +test2() { + int i; + for (; true;) { + (i,) = (42,); + break; + } + i; // Definitely assigned. +} + +test3() { + int i; + for (; true;) { + (x: i) = (x: 42); + break; + } + i; // Definitely assigned. +} + +test4() { + int i; + for (; true;) { + C(v: i) = C(42); + break; + } + i; // Definitely assigned. +} + +main() { + test1(); +} diff --git a/TypeSystem/flow-analysis/reachability_for_A03_t06.dart b/TypeSystem/flow-analysis/reachability_for_A03_t06.dart index c752d476ca..8d685c708c 100644 --- a/TypeSystem/flow-analysis/reachability_for_A03_t06.dart +++ b/TypeSystem/flow-analysis/reachability_for_A03_t06.dart @@ -15,7 +15,12 @@ /// treated by flow analysis as 'possibly assigned`. /// @author sgrekhov22@gmail.com -main() { +class C { + int v; + C(this.v); +} + +test1() { late int i; for (;; i = 42) { // Possibly assigned. https://github.com/dart-lang/sdk/issues/42232#issuecomment-690681385 break; @@ -24,3 +29,40 @@ main() { i; // Runtime error, Ok } catch (_) {} } + +test2() { + late int i; + for (;; (i,) = (42,)) { + break; + } + try { + i; // Runtime error, Ok + } catch (_) {} +} + +test3() { + late int i; + for (;; (x: i) = (x: 42)) { + break; + } + try { + i; // Runtime error, Ok + } catch (_) {} +} + +test4() { + late int i; + for (;; C(v: i) = C(42)) { + break; + } + try { + i; // Runtime error, Ok + } catch (_) {} +} + +main() { + test1(); + test2(); + test3(); + test4(); +} diff --git a/TypeSystem/flow-analysis/reachability_for_A03_t07.dart b/TypeSystem/flow-analysis/reachability_for_A03_t07.dart index ad593d93ea..d942460e96 100644 --- a/TypeSystem/flow-analysis/reachability_for_A03_t07.dart +++ b/TypeSystem/flow-analysis/reachability_for_A03_t07.dart @@ -15,7 +15,12 @@ /// then this variable is treated in `U` as 'possibly assigned`. /// @author sgrekhov22@gmail.com -main() { +class C { + int v; + C(this.v); +} + +test1() { late int i; try { for (;; i) { // Possibly assigned. https://github.com/dart-lang/sdk/issues/42232#issuecomment-690681385 @@ -24,3 +29,40 @@ main() { } } catch (_) {} } + +test2() { + late int i; + try { + for (;; i) { + continue; + (i,) = (42,); + } + } catch (_) {} +} + +test3() { + late int i; + try { + for (;; i) { + continue; + (x: i) = (x: 42); + } + } catch (_) {} +} + +test4() { + late int i; + try { + for (;; i) { + continue; + C(v: i) = C(42); + } + } catch (_) {} +} + +main() { + test1(); + test2(); + test3(); + test4(); +} diff --git a/TypeSystem/flow-analysis/reachability_for_A04_t01.dart b/TypeSystem/flow-analysis/reachability_for_A04_t01.dart index a2c94443a2..de5f4547ee 100644 --- a/TypeSystem/flow-analysis/reachability_for_A04_t01.dart +++ b/TypeSystem/flow-analysis/reachability_for_A04_t01.dart @@ -15,11 +15,58 @@ /// Test that if `C` is the `false` literal then `after(N)` is reachable. /// @author sgrekhov22@gmail.com -main() { - int i; - for (;false;) { - return; +class C { + int v; + C(this.v); +} + +test1() { + late int i; + if (2 > 1) { + for (;false;) { + return; + } + i = 42; + } + i; // Possibly assigned. +} + +test2() { + late int i; + if (2 > 1) { + for (;false;) { + return; + } + (i,) = (42,); } - i = 42; - i; // Definitely assigned. + i; +} + +test3() { + late int i; + if (2 > 1) { + for (;false;) { + return; + } + (x: i) = (x: 42); + } + i; +} + +test4() { + late int i; + if (2 > 1) { + for (;false;) { + return; + } + C(v: i) = C(42); + } + i; +} + +main() { + test1(); + test2(); + test3(); + test4(); } diff --git a/TypeSystem/flow-analysis/reachability_for_A04_t02.dart b/TypeSystem/flow-analysis/reachability_for_A04_t02.dart index ac46bbbc5b..5185b6acb0 100644 --- a/TypeSystem/flow-analysis/reachability_for_A04_t02.dart +++ b/TypeSystem/flow-analysis/reachability_for_A04_t02.dart @@ -15,11 +15,58 @@ /// Test that if `S` contains a reachable `break` then `after(N)` is reachable. /// @author sgrekhov22@gmail.com -main() { - int i; - for (;;) { - break; +class C { + int v; + C(this.v); +} + +test1() { + late int i; + if (2 > 1) { + for (;;) { + break; + } + i = 42; + } + i; // Possibly assigned. +} + +test2() { + late int i; + if (2 > 1) { + for (;;) { + break; + } + (i, ) = (42, ); } - i = 42; - i; // Definitely assigned. + i; +} + +test3() { + late int i; + if (2 > 1) { + for (;;) { + break; + } + (x: i) = (x: 42); + } + i; +} + +test4() { + late int i; + if (2 > 1) { + for (;;) { + break; + } + C(v: i) = C(42); + } + i; +} + +main() { + test1(); + test2(); + test3(); + test4(); } diff --git a/TypeSystem/flow-analysis/reachability_for_A04_t03.dart b/TypeSystem/flow-analysis/reachability_for_A04_t03.dart index b21ee55af9..5ec3716cb7 100644 --- a/TypeSystem/flow-analysis/reachability_for_A04_t03.dart +++ b/TypeSystem/flow-analysis/reachability_for_A04_t03.dart @@ -15,7 +15,12 @@ /// Test that if `S` contains a `break` then `after(N)` is reachable. /// @author sgrekhov22@gmail.com -main() { +class C { + int v; + C(this.v); +} + +test1() { late int i; if (2 > 1) { for (;;) { @@ -27,3 +32,49 @@ main() { } i; // Not definitely unassigned. } + +test2() { + late int i; + if (2 > 1) { + for (;;) { + if (2 > 1) { + break; + } + } + (i,) = (42,); + } + i; // Not definitely unassigned. +} + +test3() { + late int i; + if (2 > 1) { + for (;;) { + if (2 > 1) { + break; + } + } + (x: i) = (x: 42); + } + i; // Not definitely unassigned. +} + +test4() { + late int i; + if (2 > 1) { + for (;;) { + if (2 > 1) { + break; + } + } + C(v: i) = C(42); + } + i; // Not definitely unassigned. +} + +main() { + test1(); + test2(); + test3(); + test4(); +}