-
Notifications
You must be signed in to change notification settings - Fork 29
#3698. Add/update tests for execution #3765
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,54 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// | ||
| /// Case ⟨Synchronous non-generator functions and factory constructors⟩. Let `s` | ||
| /// be a statement of the form `return e;`. Let `f` be the immediately enclosing | ||
| /// function, and consider the case where `f` is a synchronous non-generator or | ||
| /// a factory constructor. Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. A dynamic error occurs | ||
| /// unless the dynamic type of `o` is a subtype of the actual return type of `f`. | ||
| /// Then the return statement `s` completes returning `o`. | ||
| /// | ||
| /// @description Checks that no error occurs if the run-time type of `e` is a | ||
| /// subtype of the actual return type of `f`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import 'dart:async'; | ||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| num f1() { | ||
| return 1 as dynamic; | ||
| } | ||
|
|
||
| num f2() { | ||
| return 3.14 as dynamic; | ||
| } | ||
|
|
||
| num? f3() { | ||
| return null as dynamic; | ||
| } | ||
|
|
||
| FutureOr<num> f4() { | ||
| return 4; | ||
| } | ||
|
|
||
| FutureOr<num> f5() { | ||
| return Future<num>.value(5); | ||
| } | ||
|
|
||
| int f6(v) { | ||
| return v; | ||
| } | ||
|
|
||
| main() async { | ||
| Expect.equals(1, f1()); | ||
| Expect.equals(3.14, f2()); | ||
| Expect.isNull(f3()); | ||
| Expect.equals(4, f4()); | ||
| Expect.equals(5, await f5()); | ||
| Expect.equals(6, f6(6 as num)); | ||
| } |
This file contains hidden or 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,34 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// | ||
| /// Case ⟨Synchronous non-generator functions and factory constructors⟩. Let `s` | ||
| /// be a statement of the form `return e;`. Let `f` be the immediately enclosing | ||
| /// function, and consider the case where `f` is a synchronous non-generator or | ||
| /// a factory constructor. Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. A dynamic error occurs | ||
| /// unless the dynamic type of `o` is a subtype of the actual return type of `f`. | ||
| /// Then the return statement `s` completes returning `o`. | ||
| /// | ||
| /// @description Checks that it is dynamic error if the run-time type of `e` is | ||
| /// not a subtype of the actual return type of `f`. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import 'dart:async'; | ||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| int foo(v) { | ||
| return v; | ||
| } | ||
|
|
||
| main() async { | ||
| Expect.throws(() { | ||
| foo(3.14); | ||
| }); | ||
| Expect.throws(() { | ||
| foo(null); | ||
| }); | ||
| } |
This file contains hidden or 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,60 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// ... | ||
| /// Case ⟨Asynchronous non-generator functions⟩. Let `s` be a statement of the | ||
| /// form return `e;`. Let `f` be the immediately enclosing function, and | ||
| /// consider the case where `f` is an asynchronous non-generator with future | ||
| /// value type `Tv`. | ||
| /// | ||
| /// Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. If the run-time type of | ||
| /// `o` is a subtype of `Future<Tv>`, let `v` be a fresh variable bound to `o` | ||
| /// and evaluate `await v` to an object `r`; otherwise let `r` be `o`. A dynamic | ||
| /// error occurs unless the dynamic type of `r` is a subtype of the actual value | ||
| /// of `Tv`. Then the return statement `s` completes returning `r`. | ||
| /// | ||
| /// @description Checks that if the run-time type of `o` is a subtype of | ||
| /// `Future<Tv>` then the result of `await v;` is returned. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import 'dart:async'; | ||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| Future<T> r<T>(T v) async => v; | ||
|
|
||
| Future<num> foo() async { | ||
| return r<int>(1); | ||
| } | ||
|
|
||
| FutureOr<num> bar() async { | ||
| return r<int>(2); | ||
| } | ||
|
|
||
| Future<num> baz() async { | ||
| return 3; | ||
| } | ||
|
|
||
| FutureOr<num> qux() async { | ||
| return 4; | ||
| } | ||
|
|
||
| FutureOr<Object> quux() async { | ||
| return r<Object>(5); | ||
| } | ||
|
|
||
| main() async { | ||
| Expect.notEquals(await r(1), foo()); // The expected values are directly based on the specified behavior | ||
| Expect.equals(await r(1), await foo()); | ||
| Expect.notEquals(await r(2), bar()); | ||
| Expect.equals(await r(2), await bar()); | ||
| Expect.notEquals(3, baz()); | ||
| Expect.equals(3, await baz()); | ||
| Expect.notEquals(4, qux()); | ||
| Expect.equals(4, await qux()); | ||
| Expect.notEquals(await r(5), quux()); | ||
| Expect.equals(await r(5), await quux()); | ||
| } | ||
This file contains hidden or 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,54 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// ... | ||
| /// Case ⟨Asynchronous non-generator functions⟩. Let `s` be a statement of the | ||
| /// form return `e;`. Let `f` be the immediately enclosing function, and | ||
| /// consider the case where `f` is an asynchronous non-generator with future | ||
| /// value type `Tv`. | ||
| /// | ||
| /// Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. If the run-time type of | ||
| /// `o` is a subtype of `Future<Tv>`, let `v` be a fresh variable bound to `o` | ||
| /// and evaluate `await v` to an object `r`; otherwise let `r` be `o`. A dynamic | ||
| /// error occurs unless the dynamic type of `r` is a subtype of the actual value | ||
| /// of `Tv`. Then the return statement `s` completes returning `r`. | ||
| /// | ||
| /// @description Checks that if the run-time type of `o` is a not a subtype of | ||
| /// `Future<Tv>` and not a subtype of `Tv` then dynamic error occurs. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| Future<T> r<T>(T r) async => r; | ||
|
|
||
| Future<int> foo() async { | ||
| return r<num>(1) as dynamic; | ||
| } | ||
|
|
||
| Future<int> bar() async { | ||
| return 3.14 as dynamic; | ||
| } | ||
|
|
||
| main() async { | ||
| var success = false; | ||
| asyncStart(2); | ||
| foo().then((_) { | ||
| success = true; | ||
| }).onError((_, _) { | ||
| asyncEnd(); | ||
| }).whenComplete(() { | ||
| Expect.isFalse(success); | ||
| }); | ||
|
|
||
| bar().then((_) { | ||
| success = true; | ||
| }).onError((_, _) { | ||
| asyncEnd(); | ||
| }).whenComplete(() { | ||
| Expect.isFalse(success); | ||
| }); | ||
| } |
This file contains hidden or 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,36 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// ... | ||
| /// Case ⟨Asynchronous non-generator functions⟩. Let `s` be a statement of the | ||
| /// form return `e;`. Let `f` be the immediately enclosing function, and | ||
| /// consider the case where `f` is an asynchronous non-generator with future | ||
| /// value type `Tv`. | ||
| /// | ||
| /// Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. If the run-time type of | ||
| /// `o` is a subtype of `Future<Tv>`, let `v` be a fresh variable bound to `o` | ||
| /// and evaluate `await v` to an object `r`; otherwise let `r` be `o`. A dynamic | ||
| /// error occurs unless the dynamic type of `r` is a subtype of the actual value | ||
| /// of `Tv`. Then the return statement `s` completes returning `r`. | ||
| /// | ||
| /// @description Checks that if a return statement is executing in a try-finally | ||
| /// block then finally is also executed. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| Future<num> foo() async { | ||
| try { | ||
| return 1; | ||
| } finally { | ||
| return 2; | ||
| } | ||
| } | ||
|
|
||
| main() async { | ||
| Expect.equals(2, await foo()); | ||
| } |
This file contains hidden or 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,50 @@ | ||
| // Copyright (c) 2026, 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 The execution of a return statement proceeds as follows. | ||
| /// ... | ||
| /// Case ⟨Asynchronous non-generator functions⟩. Let `s` be a statement of the | ||
| /// form return `e;`. Let `f` be the immediately enclosing function, and | ||
| /// consider the case where `f` is an asynchronous non-generator with future | ||
| /// value type `Tv`. | ||
| /// | ||
| /// Execution of `s` proceeds as follows. | ||
| /// | ||
| /// The expression `e` is evaluated to an object `o`. If the run-time type of | ||
| /// `o` is a subtype of `Future<Tv>`, let `v` be a fresh variable bound to `o` | ||
| /// and evaluate `await v` to an object `r`; otherwise let `r` be `o`. A dynamic | ||
| /// error occurs unless the dynamic type of `r` is a subtype of the actual value | ||
| /// of `Tv`. Then the return statement `s` completes returning `r`. | ||
| /// | ||
| /// @description Checks that if the run-time type of `o` is a not a subtype of | ||
| /// `Future<Tv>` then dynamic error occurs. | ||
| /// @author sgrekhov22@gmail.com | ||
| /// @issue 44395 | ||
|
|
||
| import '../../../Utils/expect.dart'; | ||
|
|
||
| Future<T> r<T>(T r) async => r; | ||
|
|
||
| Future<int> foo() async { | ||
| try { | ||
| return r<num>(1) as dynamic; | ||
|
eernstg marked this conversation as resolved.
|
||
| } on Error { | ||
| return 2; | ||
| } | ||
| } | ||
|
|
||
| Future<int> bar() async { | ||
| try { | ||
| return r<num>(1) as dynamic; | ||
| } on Error { | ||
| return 2; | ||
| } finally { | ||
| return 3; | ||
|
eernstg marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| main() async { | ||
| Expect.equals(2, await foo()); | ||
| Expect.equals(3, await bar()); | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.