Fix list tests to not set length on non-nullable lists.

The fixes to list_concurrent_modify_test are I think correct and
preserve the intent of the test. The changes to list_test get the test
working correctly and preserve the intent of the test but are
workarounds that shouldn't be needed once #42496 is fixed.

Change-Id: I82b32b2256b9940ceb934fb0f628311b8e7c6567
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152988
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2020-07-15 00:45:43 +00:00 committed by commit-bot@chromium.org
parent 845d0bdc09
commit e314030e1f
2 changed files with 14 additions and 8 deletions

View file

@ -34,8 +34,8 @@ void testConcurrentModification(List<int> list) {
// Operations that change the length cause ConcurrentModificationError.
void testModification(action()) {
testIterator(int when) {
list.length = 4;
list.setAll(0, [0, 1, 2, 3]);
list.clear();
list.addAll([0, 1, 2, 3]);
Expect.throws(() {
for (var element in list) {
if (element == when) action();
@ -44,8 +44,8 @@ void testConcurrentModification(List<int> list) {
}
testForEach(int when) {
list.length = 4;
list.setAll(0, [0, 1, 2, 3]);
list.clear();
list.addAll([0, 1, 2, 3]);
Expect.throws(() {
list.forEach((var element) {
if (element == when) action();
@ -84,7 +84,10 @@ testConcurrentAddSelf(List list) {
}
class MyList<E> extends ListBase<E> {
List<E> _source;
// TODO(42496): Use a nullable list because insert() is implemented in terms
// of length=. Change this back to `E` and remove the `as E` below when that
// issue is fixed.
List<E?> _source;
MyList(this._source);
int get length => _source.length;
void set length(int length) {
@ -95,7 +98,7 @@ class MyList<E> extends ListBase<E> {
_source.add(element);
}
E operator [](int index) => _source[index];
E operator [](int index) => _source[index] as E;
void operator []=(int index, E value) {
_source[index] = value;
}

View file

@ -546,7 +546,10 @@ class Yes {
}
class MyList<E> extends ListBase<E> {
List<E> _source;
// TODO(42496): Use a nullable list because insert() is implemented in terms
// of length=. Change this back to `E` and remove the `as E` below when that
// issue is fixed.
List<E?> _source;
MyList(this._source);
int get length => _source.length;
void set length(int length) {
@ -557,7 +560,7 @@ class MyList<E> extends ListBase<E> {
_source.add(element);
}
E operator [](int index) => _source[index];
E operator [](int index) => _source[index] as E;
void operator []=(int index, E value) {
_source[index] = value;
}