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

Side by Side Diff: tests/language/src/For2Test.dart

Issue 8490019: Capturing for loop variables correctly (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tests/language/language.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 // Dart test program for testing for statement which captures loop variable.
5
6 var f;
7
8 main() {
9 // Capture the loop variable, ensure we capture the right value.
10 for (int i = 0; i < 10; i++) {
11 if (i == 7) {
12 f = () => "i = $i";
13 }
14 }
15 Expect.equals("i = 7", f());
16
17 // There is only one instance of k. The captured variable continues
18 // to change.
19 int k;
20 for (k = 0; k < 10; k++) {
21 if (k == 7) {
22 f = () => "k = $k";
23 }
24 }
25 Expect.equals("k = 10", f());
26
27 // l gets modified after it's captured. n++ is executed on the
28 // newly introduced instance of n (i.e. the instance of the loop
29 // iteration after the value is captured).
30 for (int n = 0; n < 10; n++) {
31 var l = n;
32 if (l == 7) {
33 f = () => "l = $l, n = 7";
34 }
35 l++;
36 }
37 Expect.equals("l = 8, n = 7", f());
38 }
OLDNEW
« no previous file with comments | « tests/language/language.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698