blob: c622275dd4c7fac481abf80784db5a896e977f9d [file] [log] [blame]
// 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.
/*element: main:[null]*/
main() {
forInDirect();
forInReturn();
forInReturnMulti();
forInReturnNonNull();
}
////////////////////////////////////////////////////////////////////////////////
// For-in loop directly on a list literal.
////////////////////////////////////////////////////////////////////////////////
/*element: 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.
////////////////////////////////////////////////////////////////////////////////
/*element: 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.
////////////////////////////////////////////////////////////////////////////////
/*element: _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;
}
}
/*element: 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.
////////////////////////////////////////////////////////////////////////////////
/*element: 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;
}