46bd9f351a
This was missed in the original implementation of the sync* transformer because prior to my recent change, ScopedIds couldn't end up within a DestructuredVariable. Change-Id: I2733ce1e01edb50659634347204bac1769269615 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401080 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
32 lines
912 B
Dart
32 lines
912 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.
|
|
|
|
// Ensure optional parameters get renamed properly for sync* transformations.
|
|
|
|
Iterable<num> range(num startOrStop, [num? stop, num? step]) sync* {
|
|
final start = stop == null ? 0 : startOrStop;
|
|
stop ??= startOrStop;
|
|
step ??= 1;
|
|
|
|
if (step == 0) throw ArgumentError('step cannot be 0');
|
|
if (step > 0 && stop < start) {
|
|
throw ArgumentError('if step is positive, stop must be greater than start');
|
|
}
|
|
if (step < 0 && stop > start) {
|
|
throw ArgumentError('if step is negative, stop must be less than start');
|
|
}
|
|
|
|
for (
|
|
num value = start;
|
|
step < 0 ? value > stop : value < stop;
|
|
value += step
|
|
) {
|
|
yield value;
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
print(range(10, 20, 2));
|
|
}
|