From 403d4397589fc1d67f79ee5bee8d5ec23feb6a15 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 14 Apr 2025 13:40:28 +0300 Subject: [PATCH 1/3] #3057. Add more try-finally tests --- .../reachability_try_finally_A02_t04.dart | 2 +- .../reachability_try_finally_A02_t05.dart | 78 ++++++++++++++++ .../reachability_try_finally_A02_t06.dart | 80 ++++++++++++++++ .../reachability_try_finally_A02_t07.dart | 84 +++++++++++++++++ .../reachability_try_finally_A02_t08.dart | 88 ++++++++++++++++++ .../reachability_try_finally_A03_t09.dart | 91 ++++++++++++++++++ .../reachability_try_finally_A03_t10.dart | 92 +++++++++++++++++++ .../reachability_try_finally_A03_t11.dart | 72 +++++++++++++++ .../reachability_try_finally_A03_t12.dart | 88 ++++++++++++++++++ 9 files changed, 674 insertions(+), 1 deletion(-) create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart create mode 100644 TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t04.dart b/TypeSystem/flow-analysis/reachability_try_finally_A02_t04.dart index bea7e760a6..57f7802a57 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A02_t04.dart +++ b/TypeSystem/flow-analysis/reachability_try_finally_A02_t04.dart @@ -35,7 +35,7 @@ test1(int? n) { test2(int? n) { if (n != null) { try { - () {(n,) = (42,);}; + () {(n,) = (42,);}; } finally { n.isEven; // ^^^^^^ diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart b/TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart new file mode 100644 index 0000000000..af8268a3cc --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart @@ -0,0 +1,78 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if +/// some variable is assigned in a `catch` part of `B1` then it is +/// "possibly assigned" in `B2`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +Never foo() => throw "Never"; + +test1() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + foo(); + i = 42; + } finally { + i; // Possibly assigned + } +} + +test2(Never n) { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + n; + (i,) = (42,); + } finally { + i; + } +} + +test3(T n) { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + n; + (x: i) = (x: 42); + } finally { + i; + } +} + +test4() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + foo(); + C(v: i) = C(42); + } finally { + i; + } +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart b/TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart new file mode 100644 index 0000000000..0acbe7fcb8 --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if +/// some variable is assigned in a `catch` part of `B1` then it is +/// "possibly assigned" in `B2`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + i = 42; + } + } finally { + i; // Possibly assigned + } +} + +test2() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + (i, ) = (42, ); + } + } finally { + i; + } +} + +test3() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + (x: i) = (x: 42); + } + } finally { + i; + } +} + +test4() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + C(v: i) = C(42); + } + } finally { + i; + } +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart b/TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart new file mode 100644 index 0000000000..336c6ddc51 --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart @@ -0,0 +1,84 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if +/// some variable is assigned in a catch part of `B1` then it is +/// "possibly assigned" in `B2`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1() { + int i; + try { + print("To avoid empty body"); + } catch (_) { + i = 42; + } finally { + i; // Possibly assigned +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test2() { + int i; + try { + print("To avoid empty body"); + } catch (_) { + (i,) = (42,); + } finally { + i; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test3() { + int i; + try { + print("To avoid empty body"); + } catch (_) { + (x: i) = (x: 42); + } finally { + i; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test4() { + int i; + try { + print("To avoid empty body"); + } catch (_) { + C(v: i) = C(42); + } finally { + i; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart b/TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart new file mode 100644 index 0000000000..e31ef1f697 --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart @@ -0,0 +1,88 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if +/// some promoted variable is captured in a `catch` part of `B1` then it is +/// demoted in `B2`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1(int? n) { + if (n != null) { // `n` promoted to `int` + try { + print("To avoid empty body"); + } catch (_) { + () {n = 42;}; // `n` demoted to `int?` + } finally { + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +test2(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {(n,) = (42,);}; + } finally { + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +test3(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {(x: n) = (x: 42);}; + } finally { + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +test4(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {C(v: n) = C(42);}; + } finally { + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } + } +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart b/TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart new file mode 100644 index 0000000000..9c395f9d0c --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart @@ -0,0 +1,91 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that +/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if +/// some variable is assigned in a catch part of `B1` and it throws then it is +/// definitely unassigned in dead code `after(N)`. +/// @author sgrekhov22@gmail.com +/// @issue 60503 + +class C { + int v; + C(this.v); +} + +Never foo() => throw "Never"; + +test1() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + foo(); + i = 42; + } finally { + } + i; // Definitely unassigned and in dead code +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test2(Never n) { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + (i,) = (42,); + n; + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test3(T n) { + int i; + try { + print("To avoid empty body"); + } catch (_) { + n; + (x: i) = (x: 42); + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test4() { + int i; + try { + print("To avoid empty body"); + } catch (_) { + C(v: i) = C(42); + foo(); + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart b/TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart new file mode 100644 index 0000000000..b4cd0afed0 --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart @@ -0,0 +1,92 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that +/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if +/// some variable is assigned in dead code in catch part of `B1` then it is +/// definitely unassigned `after(N)`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + i = 42; + } + } finally { + } + i; // Definitely unassigned +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test2() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + (i,) = (42,); + } + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test3() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + (x: i) = (x: 42); + } + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +test4() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + if (false) { + C(v: i) = C(42); + } + } finally { + } + i; +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart b/TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart new file mode 100644 index 0000000000..efd6ae1d2a --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart @@ -0,0 +1,72 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that +/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if +/// some variable is assigned in a catch part of `B1` then it is "possibly +/// assigned" `after(N)`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + i = 42; + } finally { + } + i; +} + +test2() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + (i,) = (42,); + } finally { + } + i; +} + +test3() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + (x: i) = (x: 42); + } finally { + } + i; +} + +test4() { + late int i; + try { + print("To avoid empty body"); + } catch (_) { + C(v: i) = C(42); + } finally { + } + i; +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart b/TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart new file mode 100644 index 0000000000..178549bf30 --- /dev/null +++ b/TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart @@ -0,0 +1,88 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion try finally: If `N` is a try/finally statement of the form +/// `try B1 finally B2` then: +/// - Let `before(B1) = split(before(N))` +/// - Let `before(B2) = split(join(drop(after(B1)), +/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` +/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// +/// @description Checks that +/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if +/// some promoted variable is captured in a catch part of `B1` then it is +/// demoted `after(N)`. +/// @author sgrekhov22@gmail.com + +class C { + int v; + C(this.v); +} + +test1(int? n) { + if (n != null) { // `n` promoted to `int` + try { + print("To avoid empty body"); + } catch (_) { + () {n = 42;}; // `n` demoted to `int?` + } finally { + } + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test2(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {(n,) = (42,);}; + } finally { + } + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test3(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {(x: n) = (x: 42);}; + } finally { + } + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +test4(int? n) { + if (n != null) { + try { + print("To avoid empty body"); + } catch (_) { + () {C(v: n) = C(42);}; + } finally { + } + n.isEven; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +main() { + print(test1); + print(test2); + print(test3); + print(test4); +} From 09b42445099dd1095d38be61b9915bdb635ae05c Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 16 Apr 2025 13:09:30 +0300 Subject: [PATCH 2/3] Rename to try_catch_finally_*, change assertions --- ...achability_try_catch_finally_A01_t01.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A01_t02.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A01_t03.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A01_t04.dart} | 24 ++++++++---------- ...achability_try_catch_finally_A02_t01.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A02_t02.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A02_t03.dart} | 25 ++++++++----------- ...achability_try_catch_finally_A02_t04.dart} | 25 ++++++++----------- 8 files changed, 88 insertions(+), 111 deletions(-) rename TypeSystem/flow-analysis/{reachability_try_finally_A02_t05.dart => reachability_try_catch_finally_A01_t01.dart} (54%) rename TypeSystem/flow-analysis/{reachability_try_finally_A02_t06.dart => reachability_try_catch_finally_A01_t02.dart} (54%) rename TypeSystem/flow-analysis/{reachability_try_finally_A02_t07.dart => reachability_try_catch_finally_A01_t03.dart} (56%) rename TypeSystem/flow-analysis/{reachability_try_finally_A02_t08.dart => reachability_try_catch_finally_A01_t04.dart} (63%) rename TypeSystem/flow-analysis/{reachability_try_finally_A03_t09.dart => reachability_try_catch_finally_A02_t01.dart} (60%) rename TypeSystem/flow-analysis/{reachability_try_finally_A03_t10.dart => reachability_try_catch_finally_A02_t02.dart} (60%) rename TypeSystem/flow-analysis/{reachability_try_finally_A03_t11.dart => reachability_try_catch_finally_A02_t03.dart} (51%) rename TypeSystem/flow-analysis/{reachability_try_finally_A03_t12.dart => reachability_try_catch_finally_A02_t04.dart} (63%) diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart similarity index 54% rename from TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart index af8268a3cc..0ca33b20d2 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A02_t05.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if -/// some variable is assigned in a `catch` part of `B1` then it is -/// "possibly assigned" in `B2`. +/// @description Checks that if some variable is assigned in `Si` then it is +/// "possibly assigned" in `F`. /// @author sgrekhov22@gmail.com class C { @@ -25,7 +26,6 @@ Never foo() => throw "Never"; test1() { late int i; try { - print("To avoid empty body"); } catch (_) { foo(); i = 42; @@ -37,7 +37,6 @@ test1() { test2(Never n) { late int i; try { - print("To avoid empty body"); } catch (_) { n; (i,) = (42,); @@ -49,7 +48,6 @@ test2(Never n) { test3(T n) { late int i; try { - print("To avoid empty body"); } catch (_) { n; (x: i) = (x: 42); @@ -61,7 +59,6 @@ test3(T n) { test4() { late int i; try { - print("To avoid empty body"); } catch (_) { foo(); C(v: i) = C(42); diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t02.dart similarity index 54% rename from TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t02.dart index 0acbe7fcb8..808f7b19f9 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A02_t06.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t02.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if -/// some variable is assigned in a `catch` part of `B1` then it is -/// "possibly assigned" in `B2`. +/// @description Checks that if some variable is assigned in `Si` then it is +/// "possibly assigned" in `F`. /// @author sgrekhov22@gmail.com class C { @@ -23,7 +24,6 @@ class C { test1() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { i = 42; @@ -36,7 +36,6 @@ test1() { test2() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { (i, ) = (42, ); @@ -49,7 +48,6 @@ test2() { test3() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { (x: i) = (x: 42); @@ -62,7 +60,6 @@ test3() { test4() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { C(v: i) = C(42); diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t03.dart similarity index 56% rename from TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t03.dart index 336c6ddc51..d139f2d2bf 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A02_t07.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t03.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if -/// some variable is assigned in a catch part of `B1` then it is -/// "possibly assigned" in `B2`. +/// @description Checks that if some variable is assigned in `Si` then it is +/// "possibly assigned" in `F`. /// @author sgrekhov22@gmail.com class C { @@ -23,7 +24,6 @@ class C { test1() { int i; try { - print("To avoid empty body"); } catch (_) { i = 42; } finally { @@ -37,7 +37,6 @@ test1() { test2() { int i; try { - print("To avoid empty body"); } catch (_) { (i,) = (42,); } finally { @@ -51,7 +50,6 @@ test2() { test3() { int i; try { - print("To avoid empty body"); } catch (_) { (x: i) = (x: 42); } finally { @@ -65,7 +63,6 @@ test3() { test4() { int i; try { - print("To avoid empty body"); } catch (_) { C(v: i) = C(42); } finally { diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t04.dart similarity index 63% rename from TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t04.dart index e31ef1f697..e7341afe68 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A02_t08.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t04.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))`. Test that if -/// some promoted variable is captured in a `catch` part of `B1` then it is -/// demoted in `B2`. +/// @description Checks that if some promoted variable is captured in `Si` then +/// it is demoted in `F`. /// @author sgrekhov22@gmail.com class C { @@ -38,7 +39,6 @@ test1(int? n) { test2(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {(n,) = (42,);}; } finally { @@ -53,7 +53,6 @@ test2(int? n) { test3(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {(x: n) = (x: 42);}; } finally { @@ -68,7 +67,6 @@ test3(int? n) { test4(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {C(v: n) = C(42);}; } finally { diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t01.dart similarity index 60% rename from TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t01.dart index 9c395f9d0c..47805f2415 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A03_t09.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t01.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that -/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if -/// some variable is assigned in a catch part of `B1` and it throws then it is -/// definitely unassigned in dead code `after(N)`. +/// @description Checks that if some variable is assigned in `Si` and it throws +/// then it is definitely unassigned in dead code `after(N)`. /// @author sgrekhov22@gmail.com /// @issue 60503 @@ -26,7 +27,6 @@ Never foo() => throw "Never"; test1() { late int i; try { - print("To avoid empty body"); } catch (_) { foo(); i = 42; @@ -41,7 +41,6 @@ test1() { test2(Never n) { late int i; try { - print("To avoid empty body"); } catch (_) { (i,) = (42,); n; @@ -56,7 +55,6 @@ test2(Never n) { test3(T n) { int i; try { - print("To avoid empty body"); } catch (_) { n; (x: i) = (x: 42); @@ -71,7 +69,6 @@ test3(T n) { test4() { int i; try { - print("To avoid empty body"); } catch (_) { C(v: i) = C(42); foo(); diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t02.dart similarity index 60% rename from TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t02.dart index b4cd0afed0..45fd9e2b70 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A03_t10.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t02.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that -/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if -/// some variable is assigned in dead code in catch part of `B1` then it is -/// definitely unassigned `after(N)`. +/// @description Checks that if some variable is assigned in dead code in `Si` +/// then it is definitely unassigned `after(N)`. /// @author sgrekhov22@gmail.com class C { @@ -23,7 +24,6 @@ class C { test1() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { i = 42; @@ -39,7 +39,6 @@ test1() { test2() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { (i,) = (42,); @@ -55,7 +54,6 @@ test2() { test3() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { (x: i) = (x: 42); @@ -71,7 +69,6 @@ test3() { test4() { late int i; try { - print("To avoid empty body"); } catch (_) { if (false) { C(v: i) = C(42); diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t03.dart similarity index 51% rename from TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t03.dart index efd6ae1d2a..c2a0223819 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A03_t11.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t03.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that -/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if -/// some variable is assigned in a catch part of `B1` then it is "possibly -/// assigned" `after(N)`. +/// @description Checks that if some variable is assigned in `Si` then it is +/// "possibly assigned" `after(N)`. /// @author sgrekhov22@gmail.com class C { @@ -23,7 +24,6 @@ class C { test1() { late int i; try { - print("To avoid empty body"); } catch (_) { i = 42; } finally { @@ -34,7 +34,6 @@ test1() { test2() { late int i; try { - print("To avoid empty body"); } catch (_) { (i,) = (42,); } finally { @@ -45,7 +44,6 @@ test2() { test3() { late int i; try { - print("To avoid empty body"); } catch (_) { (x: i) = (x: 42); } finally { @@ -56,7 +54,6 @@ test3() { test4() { late int i; try { - print("To avoid empty body"); } catch (_) { C(v: i) = C(42); } finally { diff --git a/TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t04.dart similarity index 63% rename from TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart rename to TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t04.dart index 178549bf30..bbaaea54bc 100644 --- a/TypeSystem/flow-analysis/reachability_try_finally_A03_t12.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A02_t04.dart @@ -2,17 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @assertion try finally: If `N` is a try/finally statement of the form -/// `try B1 finally B2` then: -/// - Let `before(B1) = split(before(N))` -/// - Let `before(B2) = split(join(drop(after(B1)), -/// conservativeJoin(before(N), assignedIn(B1), capturedIn(B1))))` -/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))` +/// @assertion try catch finally: If `N` is a try/catch/finally statement of the +/// form `try B1 alternatives finally F` then: +/// - Let `before(B1) = before(N)` +/// - Let `before(Si) = join(after(B1), conservativeJoin(before(N), +/// assignedIn(B1), capturedIn(B1)))`, where `Si` +/// is the body of the i'th alternative +/// - Let +/// `after(N) = join(attachFinally(after(B1), before(F), after(F)), M1 .. Mk)` +/// where `Mj = attachFinally(after(Sj), before(F), after(F))` /// -/// @description Checks that -/// `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`. Test that if -/// some promoted variable is captured in a catch part of `B1` then it is -/// demoted `after(N)`. +/// @description Checks that if some promoted variable is captured in `Si` then +/// it is demoted `after(N)`. /// @author sgrekhov22@gmail.com class C { @@ -23,7 +24,6 @@ class C { test1(int? n) { if (n != null) { // `n` promoted to `int` try { - print("To avoid empty body"); } catch (_) { () {n = 42;}; // `n` demoted to `int?` } finally { @@ -38,7 +38,6 @@ test1(int? n) { test2(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {(n,) = (42,);}; } finally { @@ -53,7 +52,6 @@ test2(int? n) { test3(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {(x: n) = (x: 42);}; } finally { @@ -68,7 +66,6 @@ test3(int? n) { test4(int? n) { if (n != null) { try { - print("To avoid empty body"); } catch (_) { () {C(v: n) = C(42);}; } finally { From b6e64907bdb625b56c477dbae160007a8e3e1d03 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 16 Apr 2025 13:10:56 +0300 Subject: [PATCH 3/3] Add TODO --- .../flow-analysis/reachability_try_catch_finally_A01_t01.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart index 0ca33b20d2..a52a62f8ee 100644 --- a/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart +++ b/TypeSystem/flow-analysis/reachability_try_catch_finally_A01_t01.dart @@ -30,7 +30,7 @@ test1() { foo(); i = 42; } finally { - i; // Possibly assigned + i; // Possibly assigned // TODO (sgrekhov) https://github.com/dart-lang/co19/pull/3145/files#r2044357821 } }