| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "dart:async"; | 5 import "dart:async"; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 | 8 |
| 9 | 9 |
| 10 post0(a) async { | 10 post0(a) async { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 sum(a) async { | 26 sum(a) async { |
| 27 var s = 0; | 27 var s = 0; |
| 28 for (int i = 0; i < a.length; /* nothing */) { | 28 for (int i = 0; i < a.length; /* nothing */) { |
| 29 s += a[await i++]; | 29 s += a[await i++]; |
| 30 } | 30 } |
| 31 return s; | 31 return s; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Adapted from repro case for issue 22875. |
| 35 sum2(n) async { |
| 36 int i, s = 0; |
| 37 for (i = 1; i <= n; await i++) { |
| 38 // The loop-local variable j was necessary for the crash in 22785. |
| 39 var j = await i; |
| 40 s += j; |
| 41 } |
| 42 return s; |
| 43 } |
| 44 |
| 34 test() async { | 45 test() async { |
| 35 Expect.equals(10, await post0(10)); | 46 Expect.equals(10, await post0(10)); |
| 36 Expect.equals(21, await post1(10)); | 47 Expect.equals(21, await post1(10)); |
| 37 Expect.equals(11, await pref0(10)); | 48 Expect.equals(11, await pref0(10)); |
| 38 Expect.equals(23, await pref1(10)); | 49 Expect.equals(23, await pref1(10)); |
| 39 Expect.equals(10, await sum([1, 2, 3, 4])); | 50 Expect.equals(10, await sum([1, 2, 3, 4])); |
| 51 Expect.equals(10, await sum2(4)); |
| 40 } | 52 } |
| 41 | 53 |
| 42 main() { | 54 main() { |
| 43 asyncStart(); | 55 asyncStart(); |
| 44 test().then((_) { | 56 test().then((_) { |
| 45 asyncEnd(); | 57 asyncEnd(); |
| 46 }); | 58 }); |
| 47 } | 59 } |
| OLD | NEW |