dart-sdk/tests/language/await_for_use_local_test.dart
sigurdm@google.com 6787beb0f6 Analyze locals in await for loops as inside a try-finally.
Otherwise they do not get the right boxing behavior.

BUG=
R=floitsch@google.com

Review URL: https://codereview.chromium.org//964553004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44166 260f80e4-7a28-3924-810f-c04153c831b5
2015-03-03 12:41:10 +00:00

40 lines
907 B
Dart

// Copyright (c) 2015, 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
sumStream(s) async {
int accum = 0;
await for (var v in s) {
accum += v;
}
return accum;
}
test() async {
var countStreamController;
int i = 0;
void tick() {
if (i < 10) {
countStreamController.add(i);
i++;
scheduleMicrotask(tick);
} else {
countStreamController.close();
}
}
countStreamController = new StreamController(
onListen: () {
scheduleMicrotask(tick);
});
Expect.equals(45, await sumStream(countStreamController.stream));
}
void main() {
asyncStart();
test().then((_) => asyncEnd());
}