20faaa5d94
Change-Id: Ib18f554c1076f27a3f7c0df5a36410da41a1f467 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148784 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
85 lines
2.8 KiB
Dart
85 lines
2.8 KiB
Dart
// Copyright (c) 2017, 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.
|
|
|
|
// @dart = 2.7
|
|
|
|
/*member: main:[null]*/
|
|
main() {
|
|
forInDirect();
|
|
forInReturn();
|
|
forInReturnMulti();
|
|
forInReturnNonNull();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// For-in loop directly on a list literal.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*member: forInDirect:[null]*/
|
|
forInDirect() {
|
|
/*iterator: Container([exact=JSExtendableArray], element: [exact=JSUInt31], length: 3)*/
|
|
/*current: [exact=ArrayIterator]*/
|
|
/*moveNext: [exact=ArrayIterator]*/
|
|
for (var a in [1, 2, 3]) {
|
|
print(a);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Return element from a for-in loop on a list literal.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*member: forInReturn:[null|subclass=JSInt]*/
|
|
forInReturn() {
|
|
/*iterator: Container([exact=JSExtendableArray], element: [exact=JSUInt31], length: 3)*/
|
|
/*current: [exact=ArrayIterator]*/
|
|
/*moveNext: [exact=ArrayIterator]*/
|
|
for (var a in [1, 2, 3]) {
|
|
// TODO(johnniwinther): We should know the type of [a] here.
|
|
return a;
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Return element from a for-in loop on known list type.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*member: _forInReturn:[null|subclass=Object]*/
|
|
_forInReturn(
|
|
/*Container([exact=JSExtendableArray], element: [exact=JSUInt31], length: null)*/ list) {
|
|
/*iterator: Container([exact=JSExtendableArray], element: [exact=JSUInt31], length: null)*/
|
|
/*current: [exact=ArrayIterator]*/
|
|
/*moveNext: [exact=ArrayIterator]*/
|
|
for (var a in list) {
|
|
// TODO(johnniwinther): We should know the type of [a] here.
|
|
return a;
|
|
}
|
|
}
|
|
|
|
/*member: forInReturnMulti:[null]*/
|
|
forInReturnMulti() {
|
|
_forInReturn([1, 2]);
|
|
_forInReturn([1, 2, 3]);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Sequentially refine that an element is not null and return it from a for-in
|
|
// loop on known list type.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*member: forInReturnNonNull:[subclass=JSInt]*/
|
|
forInReturnNonNull() {
|
|
/*iterator: Container([exact=JSExtendableArray], element: [exact=JSUInt31], length: 3)*/
|
|
/*current: [exact=ArrayIterator]*/
|
|
/*moveNext: [exact=ArrayIterator]*/
|
|
for (var a in [1, 2, 3]) {
|
|
// TODO(johnniwinther): We should know the type of [a] here. Even if [a] has
|
|
// type `dynamic`.
|
|
a. /*[null|subclass=JSInt]*/ isEven;
|
|
a. /*[subclass=JSInt]*/ isEven;
|
|
return a;
|
|
}
|
|
return 0;
|
|
}
|