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

Side by Side Diff: pkg/kernel/testcases/closures/loop2.dart

Issue 3000333002: Fix several bugs in closure conversion. (Closed)
Patch Set: Comments. Created 3 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4 //
5 // Check that a variable declared and captured inside a loop is given a separate
6 // context for each iteration of the loop, so changes to the variable in
7 // subsequent iterations are not visible to closures capturing it in prior
8 // iterations.
9
10 void doit(int x) {
11 final int max = 10;
12 final double expectedSum = ((max - 1) * max) / 2;
13
14 int counter = 0;
15 var calls = [];
16 while (counter < max) {
17 int pos = counter;
18 calls.add(() => pos + x);
19 counter++;
20 }
21
22 double sum = 0.0;
23 for (var c in calls) sum += c();
24 if (sum != expectedSum)
25 throw new Exception("Unexpected sum = $sum != $expectedSum");
26 }
27
28 void main() {
29 doit(0);
30 }
OLDNEW
« no previous file with comments | « pkg/kernel/testcases/closures/for_in_closure.dart.expect ('k') | pkg/kernel/testcases/closures/loop2.dart.expect » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698