Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: tests/lib/async/future_test.dart

Issue 1966523003: Make _Future._chainForeignFuture not cause an assert. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/future_test.dart
diff --git a/tests/lib/async/future_test.dart b/tests/lib/async/future_test.dart
index e8387bfd19e1a159fbda3c9c6f5e508b44d668ce..c3bd46c22f18f7297e5d1c3771fbd30321079572 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -994,6 +994,27 @@ void testAnyIgnoreError() {
cs[0].completeError("BAD");
}
+void testFutureResult() {
+ asyncStart();
+ () async {
+ var f = new Feature(5);
+ f.then((v) { Expect.isTrue(v is Future); }); // Feature is designed that way.
floitsch 2016/05/10 15:39:51 long line.
Lasse Reichstein Nielsen 2016/05/11 10:19:37 Done.
+ var v = await f;
+ // The static type of await is Flatten(static-type-of-expression), so it
+ // suggests that it flattens. In practice it currently doesn't.
+ // The specification doesn't say anything special, so v should be the
+ // completion value of the Feature future which is a future.
+ Expect.isTrue(v is Future);
+
+ // This used to hit an assert in checked mode.
+ // The CL adding this test changed the behavior to actually flatten the
+ // the future returned by the then-callback.
+ var w = new Future.value(42).then((_) => f);
+ Expect.equals(42, await w);
+ asyncEnd();
+ }();
+}
+
main() {
asyncStart();
@@ -1062,6 +1083,8 @@ main() {
testAnyIgnoreIncomplete();
testAnyIgnoreError();
+ testFutureResult();
+
asyncEnd();
}
@@ -1098,3 +1121,18 @@ class BadFuture<T> implements Future<T> {
throw "timeout GOTCHA!";
}
}
+
+// Bad future that completes with another future.
+class Feature implements Future<dynamic> {
floitsch 2016/05/10 15:39:51 Please rename. It took me several attempts to read
Lasse Reichstein Nielsen 2016/05/11 10:19:37 Done. Now being clever in a more easily distinguis
+ final _result;
+ Feature(int badness) : _result = badness == 0 ? 42 : new Feature(badness - 1);
+ Future then(action(value), {onError(error, StackTrace stack)}) {
+ var c = new Completer();
+ c.complete(new Future.microtask(() => action(_result)));
+ return c.future;
+ }
+ Future catchError(onError, {test}) {} // Never an error.
+ Future whenComplete(action()) {
+ return new Future.microtask(action).then((_) => this);
+ }
+}
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698