Skip to content

Commit c798bd8

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/nnbd] Fix element type nullability check in _GrowableList.length=
When growing an array, we're checking if element type is nullable. The problem is that 'null is! T' is true for legacy types T (other than top types and Null), so it throws for List<int*>. In order to be able to grow arrays with all element types which can hold null (including legacy element types) this test is changed to null as T; which throws type error if T cannot hold null. Change-Id: Icf0a397109945b049b4aaead4c7eab11d903c45b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134790 Reviewed-by: Liam Appelbe <[email protected]> Reviewed-by: Régis Crelier <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent d854375 commit c798bd8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

sdk_nnbd/lib/_internal/vm/lib/growable_array.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ class _GrowableList<T> extends ListBase<T> {
116116
int old_capacity = _capacity;
117117
int new_capacity = new_length;
118118
if (new_capacity > old_capacity) {
119-
if (null is! T) {
120-
throw UnsupportedError(
121-
"Cannot grow array with non-nullable element type");
122-
}
119+
// Verify that element type is nullable.
120+
null as T;
123121
_grow(new_capacity);
124122
_setLength(new_length);
125123
return;

0 commit comments

Comments
 (0)