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

Unified Diff: tests/language/regress_26175_test.dart

Issue 1861963007: Dart VM: Fix an order-of-evaluation bug in async code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge upstream/master. Created 4 years, 8 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
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/regress_26175_test.dart
diff --git a/tests/language/regress_26175_test.dart b/tests/language/regress_26175_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..619afeb01da82b5a5c766b6632e7ceec8fc40a68
--- /dev/null
+++ b/tests/language/regress_26175_test.dart
@@ -0,0 +1,72 @@
+// 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.
+
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+// Test that local variable reads and writes are sequenced correctly with
+// respect to reads and writes in an awaited Future. See issue 26175.
+
+// Reads are sequenced correctly with respect to writes in a Future.
+Future test1() async {
+ var x = 'a';
+ f() async => x = 'b';
+ Expect.equals('abb', '${x}${await f()}${x}');
+}
+
+// Writes are sequenced correctly with respect to writes in a Future.
+Future test2(ignore) async {
+ var x;
+ f() async => x = 'b';
+ Expect.equals('abb', '${x = 'a'}${await f()}${x}');
+}
+
+// Writes are sequenced correctly with respect to reads in a Future.
+Future test3(ignore) async {
+ var x = 'a';
+ f() async => x;
+ Expect.equals('bbb', '${x = 'b'}${await f()}${x}');
+}
+
+// Repeat the same tests for static variables.
+var cell = 'a';
+
+asyncReadCell() async => cell;
+asyncWriteCell(value) async => cell = value;
+
+Future test4(ignore) async {
+ // This test assumes that it can read the initial value of cell.
+ Expect.equals('abb', '${cell}${await asyncWriteCell('b')}${cell}');
+}
+
+Future test5(ignore) async {
+ Expect.equals('abb', '${cell = 'a'}${await asyncWriteCell('b')}${cell}');
+}
+
+Future test6(ignore) async {
+ Expect.equals('bbb', '${cell = 'b'}${await asyncReadCell()}${cell}');
+}
+
+// Test that throwing is sequenced correctly with respect to other effects.
+Future test7(ignore) async {
+ cell = 'a';
+ try {
+ Expect.equals('unreachable',
+ '${throw 0}${await asyncWriteCell('b')}${cell}');
+ } catch (_) {
+ Expect.equals('a', cell);
+ }
+}
+
+main() {
+ asyncStart();
+ test1()
+ .then(test2)
+ .then(test3)
+ .then(test4)
+ .then(test5)
+ .then(test6)
+ .then(test7)
+ .then((_) => asyncEnd());
+}
« no previous file with comments | « runtime/vm/ast_transformer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698