2f46eaaf0c
The async rewriter was ignoring these variables since they were only used for non-user variables that didn't need to be captured. Now that we use these ScopedIds for user variables we need to capture some of them. "userDefined" specifies if the variable should be captured. Change-Id: I2dbb86e1834982b59883a3d107612ee8f8e2284a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400662 Commit-Queue: Nate Biggs <natebiggs@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com>
30 lines
748 B
Dart
30 lines
748 B
Dart
// Copyright (c) 2024, 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 'package:expect/async_helper.dart';
|
|
import 'package:expect/expect.dart';
|
|
|
|
int global = -1;
|
|
|
|
Future<void> staticAsyncLoopFunction(String value) async {
|
|
Function? f;
|
|
for (var i in [1, 2, 3]) {
|
|
print(value);
|
|
final myLocal = await 'my local value';
|
|
f ??= () {
|
|
// This should capture the value from the first loop iteration.
|
|
global = i;
|
|
return myLocal;
|
|
};
|
|
}
|
|
f!();
|
|
}
|
|
|
|
void main() async {
|
|
asyncStart();
|
|
await staticAsyncLoopFunction('foo');
|
|
Expect.equals(global, 1);
|
|
asyncEnd();
|
|
}
|