-
Notifications
You must be signed in to change notification settings - Fork 28
#1363 Async for-in
test updated according to the current specification
#1379
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
5 commits
Select commit
Hold shift + click to select a range
b4e3f3c
#1363. Async for-in tests updated and new ones added
sgrekhov ff2067c
#1363. Async for-in tests refactored, fixed and new ones added
sgrekhov 8e05690
#1363. More async for-in tests added
sgrekhov 3dbe9a4
#1363. Excessive delays removed
sgrekhov bf4c337
#1363. Minor changes according to the review notes
sgrekhov 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
73 changes: 73 additions & 0 deletions
73
Language/Statements/For/Asynchronous_For_in/execution_A01_t01.dart
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,73 @@ | ||
// Copyright (c) 2015, 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 Let `D` be derived from <finalConstVarOrType>?. Execution of a | ||
/// for-in statement, `f`, of the form `await for (D id in e) s` proceeds as | ||
/// follows: | ||
/// | ||
/// The expression `e` is evaluated to an object `o`. It is a dynamic type error | ||
/// if `o` is not an instance of a class that implements [Stream]. It is a | ||
/// compile-time error if `D` is empty and `id` is a final variable. | ||
/// | ||
/// The stream associated with the innermost enclosing asynchronous for loop, | ||
/// if any, is paused. The stream `o` is listened to, producing a stream | ||
/// subscription `u`, and execution of the asynchronous for-in loop is suspended | ||
/// until a stream event is available. | ||
/// | ||
/// Pausing an asynchronous for loop means pausing the associated stream | ||
/// subscription. A stream subscription is paused by calling its pause method. | ||
/// If the subscription is already paused, an implementation may omit further | ||
/// calls to pause. | ||
/// | ||
/// For each data event from `u`, the statement `s` is executed with `id` bound | ||
/// to the value of the current data event. | ||
/// | ||
/// If execution of `s` continues without a label, or to a label that prefixes | ||
/// the asynchronous for statement, then the execution of `s` is treated as if | ||
/// it had completed normally. | ||
/// | ||
/// If execution of `s` otherwise does not complete normally, the subscription | ||
/// `u` is canceled by evaluating `await v.cancel()` where `v` is a fresh | ||
/// variable referencing the stream subscription `u`. If that evaluation throws, | ||
/// execution of `f` throws the same exception and stack trace. Otherwise | ||
/// execution of `f` completes in the same way as the execution of `s`. | ||
/// Otherwise the execution of `f` is suspended again, waiting for the next | ||
/// stream subscription event, and `u` is resumed if it has been paused. | ||
/// | ||
/// On an error event from `u`, with error object `e` and stack trace `st`, the | ||
/// subscription `u` is canceled by evaluating `await v.cancel()` where `v` is a | ||
/// fresh variable referencing the stream subscription `u`. If that evaluation | ||
/// throws, execution of `f` throws the same exception object and stack trace. | ||
/// Otherwise execution of `f` throws with `e` as exception object and `st` as | ||
/// stack trace. | ||
/// | ||
/// When `u` is done, execution of `f` completes normally. | ||
/// | ||
/// @description Check that a compile error occurs if o is not an instance | ||
/// of a class that implements [Stream] | ||
/// | ||
/// @author [email protected] | ||
|
||
import 'dart:async'; | ||
|
||
Future test1() async { | ||
await for (var i in new Object()) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
Future test2() async { | ||
await for (int i in [1, 2, 3]) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
|
||
main() { | ||
test1(); | ||
test2(); | ||
} |
66 changes: 66 additions & 0 deletions
66
Language/Statements/For/Asynchronous_For_in/execution_A01_t02.dart
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,66 @@ | ||
// Copyright (c) 2022, 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 Let `D` be derived from <finalConstVarOrType>?. Execution of a | ||
/// for-in statement, `f`, of the form `await for (D id in e) s` proceeds as | ||
/// follows: | ||
/// | ||
/// The expression `e` is evaluated to an object `o`. It is a dynamic type error | ||
/// if `o` is not an instance of a class that implements [Stream]. It is a | ||
/// compile-time error if `D` is empty and `id` is a final variable. | ||
/// | ||
/// The stream associated with the innermost enclosing asynchronous for loop, | ||
/// if any, is paused. The stream `o` is listened to, producing a stream | ||
/// subscription `u`, and execution of the asynchronous for-in loop is suspended | ||
/// until a stream event is available. | ||
/// | ||
/// Pausing an asynchronous for loop means pausing the associated stream | ||
/// subscription. A stream subscription is paused by calling its pause method. | ||
/// If the subscription is already paused, an implementation may omit further | ||
/// calls to pause. | ||
/// | ||
/// For each data event from `u`, the statement `s` is executed with `id` bound | ||
/// to the value of the current data event. | ||
/// | ||
/// If execution of `s` continues without a label, or to a label that prefixes | ||
/// the asynchronous for statement, then the execution of `s` is treated as if | ||
/// it had completed normally. | ||
/// | ||
/// If execution of `s` otherwise does not complete normally, the subscription | ||
/// `u` is canceled by evaluating `await v.cancel()` where `v` is a fresh | ||
/// variable referencing the stream subscription `u`. If that evaluation throws, | ||
/// execution of `f` throws the same exception and stack trace. Otherwise | ||
/// execution of `f` completes in the same way as the execution of `s`. | ||
/// Otherwise the execution of `f` is suspended again, waiting for the next | ||
/// stream subscription event, and `u` is resumed if it has been paused. | ||
/// | ||
/// On an error event from `u`, with error object `e` and stack trace `st`, the | ||
/// subscription `u` is canceled by evaluating `await v.cancel()` where `v` is a | ||
/// fresh variable referencing the stream subscription `u`. If that evaluation | ||
/// throws, execution of `f` throws the same exception object and stack trace. | ||
/// Otherwise execution of `f` throws with `e` as exception object and `st` as | ||
/// stack trace. | ||
/// | ||
/// When `u` is done, execution of `f` completes normally. | ||
/// | ||
/// @description Check that it is a dynamic type error if `o` is not an instance | ||
/// of a class that implements [Stream] | ||
/// | ||
/// @author [email protected] | ||
|
||
import '../../../../Utils/expect.dart'; | ||
|
||
main() async { | ||
bool wasException = false; | ||
dynamic collection = [1, 2, 3]; | ||
try { | ||
await for (var i in collection) { | ||
Expect.fail("Dynamic error expected"); | ||
print(i); | ||
} | ||
} catch (_) { | ||
wasException = true; | ||
} | ||
Expect.isTrue(wasException); | ||
} |
60 changes: 60 additions & 0 deletions
60
Language/Statements/For/Asynchronous_For_in/execution_A01_t03.dart
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) 2022, 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 Let `D` be derived from <finalConstVarOrType>?. Execution of a | ||
/// for-in statement, `f`, of the form `await for (D id in e) s` proceeds as | ||
/// follows: | ||
/// | ||
/// The expression `e` is evaluated to an object `o`. It is a dynamic type error | ||
/// if `o` is not an instance of a class that implements [Stream]. It is a | ||
/// compile-time error if `D` is empty and `id` is a final variable. | ||
/// | ||
/// The stream associated with the innermost enclosing asynchronous for loop, | ||
/// if any, is paused. The stream `o` is listened to, producing a stream | ||
/// subscription `u`, and execution of the asynchronous for-in loop is suspended | ||
/// until a stream event is available. | ||
/// | ||
/// Pausing an asynchronous for loop means pausing the associated stream | ||
/// subscription. A stream subscription is paused by calling its pause method. | ||
/// If the subscription is already paused, an implementation may omit further | ||
/// calls to pause. | ||
/// | ||
/// For each data event from `u`, the statement `s` is executed with `id` bound | ||
/// to the value of the current data event. | ||
/// | ||
/// If execution of `s` continues without a label, or to a label that prefixes | ||
/// the asynchronous for statement, then the execution of `s` is treated as if | ||
/// it had completed normally. | ||
/// | ||
/// If execution of `s` otherwise does not complete normally, the subscription | ||
/// `u` is canceled by evaluating `await v.cancel()` where `v` is a fresh | ||
/// variable referencing the stream subscription `u`. If that evaluation throws, | ||
/// execution of `f` throws the same exception and stack trace. Otherwise | ||
/// execution of `f` completes in the same way as the execution of `s`. | ||
/// Otherwise the execution of `f` is suspended again, waiting for the next | ||
/// stream subscription event, and `u` is resumed if it has been paused. | ||
/// | ||
/// On an error event from `u`, with error object `e` and stack trace `st`, the | ||
/// subscription `u` is canceled by evaluating `await v.cancel()` where `v` is a | ||
/// fresh variable referencing the stream subscription `u`. If that evaluation | ||
/// throws, execution of `f` throws the same exception object and stack trace. | ||
/// Otherwise execution of `f` throws with `e` as exception object and `st` as | ||
/// stack trace. | ||
/// | ||
/// When `u` is done, execution of `f` completes normally. | ||
/// | ||
/// @description Check that it is a compile-time error if `D` is empty and id is | ||
/// a final variable. | ||
/// | ||
/// @author [email protected] | ||
/// @issue 49495 | ||
|
||
main() async { | ||
final i; | ||
await for (i in Stream.fromIterable(['one', 'two', 'three'])) { | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Language/Statements/For/Asynchronous_For_in/execution_A02_t01.dart
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,63 @@ | ||
// Copyright (c) 2022, 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 Let `D` be derived from <finalConstVarOrType>?. Execution of a | ||
/// for-in statement, `f`, of the form `await for (D id in e) s` proceeds as | ||
/// follows: | ||
/// | ||
/// The expression `e` is evaluated to an object `o`. It is a dynamic type error | ||
/// if `o` is not an instance of a class that implements [Stream]. It is a | ||
/// compile-time error if `D` is empty and `id` is a final variable. | ||
/// | ||
/// The stream associated with the innermost enclosing asynchronous for loop, | ||
/// if any, is paused. The stream `o` is listened to, producing a stream | ||
/// subscription `u`, and execution of the asynchronous for-in loop is suspended | ||
/// until a stream event is available. | ||
/// | ||
/// Pausing an asynchronous for loop means pausing the associated stream | ||
/// subscription. A stream subscription is paused by calling its pause method. | ||
/// If the subscription is already paused, an implementation may omit further | ||
/// calls to pause. | ||
/// | ||
/// For each data event from `u`, the statement `s` is executed with `id` bound | ||
/// to the value of the current data event. | ||
/// | ||
/// If execution of `s` continues without a label, or to a label that prefixes | ||
/// the asynchronous for statement, then the execution of `s` is treated as if | ||
/// it had completed normally. | ||
/// | ||
/// If execution of `s` otherwise does not complete normally, the subscription | ||
/// `u` is canceled by evaluating `await v.cancel()` where `v` is a fresh | ||
/// variable referencing the stream subscription `u`. If that evaluation throws, | ||
/// execution of `f` throws the same exception and stack trace. Otherwise | ||
/// execution of `f` completes in the same way as the execution of `s`. | ||
/// Otherwise the execution of `f` is suspended again, waiting for the next | ||
/// stream subscription event, and `u` is resumed if it has been paused. | ||
/// | ||
/// On an error event from `u`, with error object `e` and stack trace `st`, the | ||
/// subscription `u` is canceled by evaluating `await v.cancel()` where `v` is a | ||
/// fresh variable referencing the stream subscription `u`. If that evaluation | ||
/// throws, execution of `f` throws the same exception object and stack trace. | ||
/// Otherwise execution of `f` throws with `e` as exception object and `st` as | ||
/// stack trace. | ||
/// | ||
/// When `u` is done, execution of `f` completes normally. | ||
/// | ||
/// @description Check that the stream associated with the innermost enclosing | ||
/// asynchronous for loop is paused | ||
/// | ||
/// @author [email protected] | ||
|
||
import 'dart:async'; | ||
import '../../../../Utils/expect.dart'; | ||
|
||
main() async { | ||
StreamController<int> sc = StreamController<int>(); | ||
sc.addStream(Stream<int>.fromIterable([1, 2, 3])); | ||
await for (var i in sc.stream) { | ||
await for (var j in Stream.fromIterable(['one', 'two', 'three'])) { | ||
Expect.isTrue(sc.isPaused); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Language/Statements/For/Asynchronous_For_in/execution_A02_t02.dart
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,63 @@ | ||
// Copyright (c) 2022, 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 Let `D` be derived from <finalConstVarOrType>?. Execution of a | ||
/// for-in statement, `f`, of the form `await for (D id in e) s` proceeds as | ||
/// follows: | ||
/// | ||
/// The expression `e` is evaluated to an object `o`. It is a dynamic type error | ||
/// if `o` is not an instance of a class that implements [Stream]. It is a | ||
/// compile-time error if `D` is empty and `id` is a final variable. | ||
/// | ||
/// The stream associated with the innermost enclosing asynchronous for loop, | ||
/// if any, is paused. The stream `o` is listened to, producing a stream | ||
/// subscription `u`, and execution of the asynchronous for-in loop is suspended | ||
/// until a stream event is available. | ||
/// | ||
/// Pausing an asynchronous for loop means pausing the associated stream | ||
/// subscription. A stream subscription is paused by calling its pause method. | ||
/// If the subscription is already paused, an implementation may omit further | ||
/// calls to pause. | ||
/// | ||
/// For each data event from `u`, the statement `s` is executed with `id` bound | ||
/// to the value of the current data event. | ||
/// | ||
/// If execution of `s` continues without a label, or to a label that prefixes | ||
/// the asynchronous for statement, then the execution of `s` is treated as if | ||
/// it had completed normally. | ||
/// | ||
/// If execution of `s` otherwise does not complete normally, the subscription | ||
/// `u` is canceled by evaluating `await v.cancel()` where `v` is a fresh | ||
/// variable referencing the stream subscription `u`. If that evaluation throws, | ||
/// execution of `f` throws the same exception and stack trace. Otherwise | ||
/// execution of `f` completes in the same way as the execution of `s`. | ||
/// Otherwise the execution of `f` is suspended again, waiting for the next | ||
/// stream subscription event, and `u` is resumed if it has been paused. | ||
/// | ||
/// On an error event from `u`, with error object `e` and stack trace `st`, the | ||
/// subscription `u` is canceled by evaluating `await v.cancel()` where `v` is a | ||
/// fresh variable referencing the stream subscription `u`. If that evaluation | ||
/// throws, execution of `f` throws the same exception object and stack trace. | ||
/// Otherwise execution of `f` throws with `e` as exception object and `st` as | ||
/// stack trace. | ||
/// | ||
/// When `u` is done, execution of `f` completes normally. | ||
/// | ||
/// @description Check that execution of the asynchronous for-in loop is | ||
/// suspended until a stream event is available but not paused | ||
/// | ||
/// @author [email protected] | ||
|
||
import 'dart:async'; | ||
import '../../../../Utils/expect.dart'; | ||
|
||
main() async { | ||
StreamController<int> sc = StreamController<int>(); | ||
sc.addStream(Stream<int>.fromIterable([1, 2, 3])); | ||
await for (var j in Stream.fromIterable(['one', 'two', 'three'])) { | ||
await for (var i in sc.stream) { | ||
Expect.isFalse(sc.isPaused); | ||
} | ||
} | ||
} |
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.