forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#3057. Add flow analysis tests for throw expression
- Loading branch information
Showing
7 changed files
with
481 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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 throw: If `N` is a throw expression of the form `throw E1`, then: | ||
/// - Let `before(E1) = before(N)` | ||
/// - Let `after(N) = unreachable(after(E1))` | ||
/// | ||
/// @description Checks that a code after throw expression is unreachable. | ||
/// @author [email protected] | ||
main() { | ||
late int i; | ||
if ((() => false)()) { | ||
throw "Dead code after this point"; | ||
i = 42; // Variable is initialized in a dead code. This leaves it definitely unassigned | ||
} | ||
i; // It is an error to read a local late variable when it is definitely unassigned. | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 throw: If `N` is a throw expression of the form `throw E1`, then: | ||
/// - Let `before(E1) = before(N)` | ||
/// - Let `after(N) = unreachable(after(E1))` | ||
/// | ||
/// @description Checks that a code after throw expression is unreachable. Test | ||
/// collection literals. | ||
/// @author [email protected] | ||
test1() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
throw "Dead code after this point", | ||
i = 42 // Variable is initialized in a dead code. This leaves it definitely unassigned | ||
]; | ||
} | ||
i; // It is an error to read a local late variable when it is definitely unassigned. | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test2() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
throw "Dead code after this point", | ||
i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test3() { | ||
late int i; | ||
if ((() => false)()) { | ||
<String, int>{ | ||
"key1": 0, | ||
"key2": throw "Dead code after this point", | ||
"key3": i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test4() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int, String>{ | ||
0: "value1", | ||
throw "Dead code after this point": "value2", | ||
i = 42: "value3" | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 throw: If `N` is a throw expression of the form `throw E1`, then: | ||
/// - Let `before(E1) = before(N)` | ||
/// - Let `after(N) = unreachable(after(E1))` | ||
/// | ||
/// @description Checks that a code after throw expression is unreachable. Test | ||
/// collection literals. | ||
/// @author [email protected] | ||
test1() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
if (throw "Dead code after this point") | ||
i = 42, | ||
i = 42 | ||
]; | ||
} | ||
i; // It is an error to read a local late variable when it is definitely unassigned. | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test2() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
if (throw "Dead code after this point") | ||
i = 42, | ||
i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test3() { | ||
late int i; | ||
if ((() => false)()) { | ||
<String, int>{ | ||
"key1": 0, | ||
if (throw "Dead code after this point") | ||
"key2": i = 42, | ||
"key3": i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test4() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int, String>{ | ||
0: "value1", | ||
if (throw "Dead code after this point") | ||
i = 42: "value2", | ||
i = 0: "value3" | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 throw: If `N` is a throw expression of the form `throw E1`, then: | ||
/// - Let `before(E1) = before(N)` | ||
/// - Let `after(N) = unreachable(after(E1))` | ||
/// | ||
/// @description Checks that a code after throw expression is unreachable. Test | ||
/// `for(;;)` loop in list literals. | ||
/// @author [email protected] | ||
test1() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
for (throw "Dead code after this point";;) | ||
i = 42, | ||
i = 42 | ||
]; | ||
} | ||
i; // It is an error to read a local late variable when it is definitely unassigned. | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test2() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
for (;throw "Dead code after this point";) | ||
i = 42, | ||
i = 42 | ||
]; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test3() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
for (;; throw "Dead code after this statement") | ||
1, | ||
i = 42 | ||
]; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test4() { | ||
late int i; | ||
if ((() => false)()) { | ||
[ | ||
0, | ||
for (var j = 0; j < 0; throw "Not a dead code after this point") | ||
i = 42 | ||
]; | ||
} | ||
i; // Ok | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 throw: If `N` is a throw expression of the form `throw E1`, then: | ||
/// - Let `before(E1) = before(N)` | ||
/// - Let `after(N) = unreachable(after(E1))` | ||
/// | ||
/// @description Checks that a code after throw expression is unreachable. Test | ||
/// `for(;;)` loop in set literals. | ||
/// @author [email protected] | ||
test1() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
for (throw "Dead code after this point";;) | ||
i = 42, | ||
i = 42 | ||
}; | ||
} | ||
i; // It is an error to read a local late variable when it is definitely unassigned. | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test2() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
for (; throw "Dead code after this point";) | ||
i = 42, | ||
i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test3() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
for (;; throw "Dead code after this statement") | ||
1, | ||
i = 42 | ||
}; | ||
} | ||
i; | ||
//^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
test4() { | ||
late int i; | ||
if ((() => false)()) { | ||
<int>{ | ||
0, | ||
for (var j = 0; j < 0; throw "Not a dead code after this point") | ||
i = 42, | ||
}; | ||
} | ||
i; // Ok | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
Oops, something went wrong.