-
Notifications
You must be signed in to change notification settings - Fork 28
#3057. Add more try-catch-finally tests #3146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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 catch: If `N` is a try/catch statement of the form | ||
/// `try B alternatives` then: | ||
/// - Let `before(B) = before(N)` | ||
/// - For each catch block on `Ti Si` in alternatives: | ||
/// - Let | ||
/// `before(Si) = conservativeJoin(before(N), assignedIn(B), capturedIn(B))` | ||
/// - Let `after(N) = join(after(B), after(C0), ..., after(Ck))` | ||
/// | ||
/// @description Checks that if a type `T` is made a type of interest in | ||
/// `before(N)` then it can be promoted in `B`, `alternatives` and `after(N)`. | ||
/// @author [email protected] | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
class C { | ||
T v; | ||
C(this.v); | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
if (s is T) {} // make `T` a type of interest | ||
try { | ||
s = T(); | ||
s.answer(); | ||
} catch (_) { | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
if (s is T) {} | ||
try { | ||
} catch (_) { | ||
(s,) = (T(),); | ||
s.answer(); | ||
} | ||
} | ||
|
||
test3() { | ||
S s = S(); | ||
if (s is T) {} | ||
try { | ||
} catch (_) { | ||
} | ||
C(v: s) = C(T()); | ||
s.answer(); | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 catch: If `N` is a try/catch statement of the form | ||
/// `try B alternatives` then: | ||
/// - Let `before(B) = before(N)` | ||
/// - For each catch block on `Ti Si` in alternatives: | ||
/// - Let | ||
/// `before(Si) = conservativeJoin(before(N), assignedIn(B), capturedIn(B))` | ||
/// - Let `after(N) = join(after(B), after(C0), ..., after(Ck))` | ||
/// | ||
/// @description Checks that if a type `T` is made a type of interest in `B` | ||
/// then it can be promoted in `B`, `alternatives` and `after(N)`. | ||
/// @author [email protected] | ||
/// @issue 60519 | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
class C { | ||
T v; | ||
C(this.v); | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} // make `T` a type of interest | ||
s = T(); | ||
s.answer(); | ||
} catch (_) { | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} | ||
} catch (_) { | ||
(s,) = (T(),); | ||
s.answer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this one to fail because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But according to the dart-lang/sdk#60519 this should be an error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, it should be an error because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, I just created dart-lang/language#4328 in order to clarify the situation: The implemented behavior appears to be different from the specified behavior. |
||
} | ||
} | ||
|
||
test3() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} | ||
} catch (_) { | ||
} | ||
C(v: s) = C(T()); | ||
s.answer(); | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 catch: If `N` is a try/catch statement of the form | ||
/// `try B alternatives` then: | ||
/// - Let `before(B) = before(N)` | ||
/// - For each catch block on `Ti Si` in alternatives: | ||
/// - Let | ||
/// `before(Si) = conservativeJoin(before(N), assignedIn(B), capturedIn(B))` | ||
/// - Let `after(N) = join(after(B), after(C0), ..., after(Ck))` | ||
/// | ||
/// @description Checks that if a type `T` is made a type of interest in | ||
/// `alternatives` then it can be promoted in `alternatives` and `after(N)`. | ||
/// @author [email protected] | ||
/// @issue 60519 | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
class C { | ||
T v; | ||
C(this.v); | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
try {} catch (_) { | ||
if (s is T) {} // make `T` a type of interest | ||
s = T(); | ||
s.answer(); | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
try { | ||
} on Exception catch (_) { | ||
if (s is T) {} | ||
} catch (_) { | ||
(s,) = (T(),); | ||
s.answer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect this to fail because each alternative starts with |
||
} | ||
} | ||
|
||
test3() { | ||
S s = S(); | ||
try { | ||
} on Exception catch (_) { | ||
if (s is T) {} | ||
} | ||
C(v: s) = C(T()); | ||
s.answer(); | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 catch: If `N` is a try/catch statement of the form | ||
/// `try B alternatives` then: | ||
/// - Let `before(B) = before(N)` | ||
/// - For each catch block on `Ti Si` in alternatives: | ||
/// - Let | ||
/// `before(Si) = conservativeJoin(before(N), assignedIn(B), capturedIn(B))` | ||
/// - Let `after(N) = join(after(B), after(C0), ..., after(Ck))` | ||
/// | ||
/// @description Checks that if a type `T` is made a type of interest in | ||
/// `alternatives` then it cannot be promoted in `B`. | ||
/// @author [email protected] | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
try { | ||
s = T(); | ||
s.answer(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} catch (_) { | ||
if (s is T) {} // make `T` a type of interest | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
try { | ||
} on Exception catch (_) { | ||
s = T(); | ||
s.answer(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} catch (_) { | ||
if (s is T) {} | ||
} | ||
} | ||
|
||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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 if a type `T` is made a type of interest in | ||
/// `before(N)` then it can be promoted in `B1`, `B2` and `after(N)`. | ||
/// @author [email protected] | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
class C { | ||
T v; | ||
C(this.v); | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
if (s is T) {} // make `T` a type of interest | ||
try { | ||
s = T(); | ||
s.answer(); | ||
} finally { | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
if (s is T) {} | ||
try { | ||
} catch (_) { | ||
(s,) = (T(),); | ||
s.answer(); | ||
} finally { | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, we should certainly test try/catch/finally even though it's not yet in the spec. Best effort, as usual. ;-) But I guess they'd fit better in a series of tests named |
||
|
||
test3() { | ||
S s = S(); | ||
if (s is T) {} | ||
try { | ||
} catch (_) { | ||
} finally { | ||
(x: s) = (x: T()); | ||
s.answer(); | ||
} | ||
} | ||
|
||
test4() { | ||
S s = S(); | ||
if (s is T) {} | ||
try { | ||
} catch (_) { | ||
} finally { | ||
} | ||
C(v: s) = C(T()); | ||
s.answer(); | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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 if a type `T` is made a type of interest in `B1` | ||
/// then it can be promoted in `B1`, `B2` and `after(N)`. | ||
/// @author [email protected] | ||
/// @issue 60519 | ||
|
||
class S {} | ||
|
||
class T extends S { | ||
int answer() => 42; | ||
} | ||
|
||
class C { | ||
T v; | ||
C(this.v); | ||
} | ||
|
||
test1() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} // make `T` a type of interest | ||
s = T(); | ||
s.answer(); | ||
} finally { | ||
} | ||
} | ||
|
||
test2() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} | ||
} catch (_) { | ||
(s,) = (T(),); | ||
s.answer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one should again fail, considering that the catch blocks have no more than |
||
} finally { | ||
} | ||
} | ||
|
||
test3() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} | ||
} catch (_) { | ||
} finally { | ||
(x: s) = (x: T()); | ||
s.answer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
} | ||
} | ||
|
||
test4() { | ||
S s = S(); | ||
try { | ||
if (s is T) {} | ||
} catch (_) { | ||
} finally { | ||
} | ||
C(v: s) = C(T()); | ||
s.answer(); | ||
} | ||
|
||
main() { | ||
print(test1); | ||
print(test2); | ||
print(test3); | ||
print(test4); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.