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 @@ |
+/* |
+ * 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); |
+} |