dart-sdk/tests/corelib/regress_42502_test.dart
Alexander Markov e6cbfd71f1 [vm/corelib/nnbd] Fix null check in _GrowableList.length=
We should verify that element type is nullable every time length is
increased, not only when capacity is increased.

Fixes https://github.com/dart-lang/sdk/issues/42502

Change-Id: Id91c702a99028634da8c2d41ae0ceac521af2cf5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152900
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-06-30 17:14:14 +00:00

28 lines
709 B
Dart

// Copyright (c) 2020, 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.
// Regression test for https://github.com/dart-lang/sdk/issues/42502.
// Requirements=nnbd-strong
import "package:expect/expect.dart";
void main() {
List<int> x = [];
Expect.throws(() {
x.length = x.length + 1;
});
Expect.equals(0, x.length);
x.add(222);
Expect.equals(1, x.length);
Expect.throws(() {
x.length = 2;
});
Expect.equals(1, x.length);
Expect.throws(() {
x.length = x.length + 1;
});
Expect.equals(1, x.length);
Expect.equals(222, x[0]);
}