Add missing offset to yield produced by await for
Fixes #36069.
Fixes #28916.
Change-Id: I1acc6b9f0aaba100827749a1f3653f5cc9e4fd2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98665
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
diff --git a/pkg/kernel/lib/transformations/continuation.dart b/pkg/kernel/lib/transformations/continuation.dart
index a78a3ab..b599cdf 100644
--- a/pkg/kernel/lib/transformations/continuation.dart
+++ b/pkg/kernel/lib/transformations/continuation.dart
@@ -747,7 +747,8 @@
new VariableGet(iteratorVariable),
new Name('moveNext'),
new Arguments(<Expression>[]),
- helper.streamIteratorMoveNext));
+ helper.streamIteratorMoveNext))
+ ..fileOffset = stmt.fileOffset;
// _asyncStarMoveNextHelper(:stream)
var asyncStarMoveNextCall = new StaticInvocation(
diff --git a/runtime/observatory/tests/service/next_through_await_for_test.dart b/runtime/observatory/tests/service/next_through_await_for_test.dart
new file mode 100644
index 0000000..734c1f1
--- /dev/null
+++ b/runtime/observatory/tests/service/next_through_await_for_test.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2019, 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 'test_helper.dart';
+import 'service_test_common.dart';
+
+const int LINE = 14;
+const String file = "next_through_await_for_test.dart";
+
+code() async {
+ int count = 0;
+ await for (var num in naturalsTo(2)) {
+ print(num);
+ count++;
+ }
+}
+
+Stream<int> naturalsTo(int n) async* {
+ int k = 0;
+ while (k < n) {
+ k++;
+ yield k;
+ }
+ yield 42;
+}
+
+List<String> stops = [];
+List<String> expected = [
+ "$file:${LINE + 0}:13", // on '='
+ "$file:${LINE + 1}:25", // on 'naturalsTo'
+
+ // Iteration #1
+ "$file:${LINE + 1}:3", // on 'await'
+ "$file:${LINE + 1}:40", // on '{'
+ "$file:${LINE + 2}:5", // on 'print'
+ "$file:${LINE + 3}:10", // on '++'
+
+ // Iteration #2
+ "$file:${LINE + 1}:3", // on 'await'
+ "$file:${LINE + 1}:40", // on '{'
+ "$file:${LINE + 2}:5", // on 'print'
+ "$file:${LINE + 3}:10", // on '++'
+
+ // Iteration #3
+ "$file:${LINE + 1}:3", // on 'await'
+ "$file:${LINE + 1}:40", // on '{'
+ "$file:${LINE + 2}:5", // on 'print'
+ "$file:${LINE + 3}:10", // on '++'
+
+ // Done
+ "$file:${LINE + 1}:3", // on 'await'
+ "$file:${LINE + 5}:1"
+];
+
+var tests = <IsolateTest>[
+ hasPausedAtStart,
+ setBreakpointAtLine(LINE),
+ runStepThroughProgramRecordingStops(stops),
+ checkRecordedStops(stops, expected,
+ debugPrint: true, debugPrintFile: file, debugPrintLine: LINE)
+];
+
+main(args) {
+ runIsolateTestsSynchronous(args, tests,
+ testeeConcurrent: code, pause_on_start: true, pause_on_exit: true);
+}