Index: pkg/kernel/testcases/closures/loop2.dart |
diff --git a/pkg/kernel/testcases/closures/loop2.dart b/pkg/kernel/testcases/closures/loop2.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..969516e015f06c4e4dcb101b16c3609e5169b07b |
--- /dev/null |
+++ b/pkg/kernel/testcases/closures/loop2.dart |
@@ -0,0 +1,26 @@ |
+/* |
Dmitry Stefantsov
2017/08/24 11:49:57
Please, use one-line comments in the preamble and
sjindel
2017/08/24 14:50:13
Done, but why does it matter?
Dmitry Stefantsov
2017/08/24 15:07:28
So that the next reader experiences less distracti
sjindel
2017/08/24 15:14:11
I think this is Green vs. Orange thinking :P
Dmitry Stefantsov
2017/08/24 15:17:28
Or Gold ;)
|
+ * Copyright (c) 2017, 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. |
+ */ |
+void doit(int x) { |
+ final int max = 10; |
+ final double expectedSum = ((max - 1) * max) / 2; |
+ |
+ int counter = 0; |
+ var calls = []; |
+ while (counter < max) { |
+ int pos = counter; |
+ calls.add(() => pos + x); |
+ counter++; |
+ } |
+ |
+ double sum = 0.0; |
+ for (var c in calls) sum += c(); |
+ if (sum != expectedSum) |
+ throw new Exception("Unexpected sum = $sum != $expectedSum"); |
+} |
+ |
+void main() { |
+ doit(0); |
+} |