Open
Description
Using
import 'dart:collection';
void main() {
{
var list = [];
// works
list.length = 1;
print('Length: ${list.length}');
}
{
var list = <Object>[];
// throws
list.length = 1;
print('Length: ${list.length}');
}
}
Expected
I suspect that the list cannot grow by adding Null elements due to null safety, so the code should throw, but it would be great to have a better error message. Even better, is it possible to give a compilation error instead?
Actual
Unhandled exception:
type 'Null' is not a subtype of type 'Object' in type cast
#0 List.length= (dart:core-patch/growable_array.dart:222:12)
#1 main (file:///Users/annagrin/source/try/notAListBug/main.dart:14:10)
#2 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Dart SDK version
Dart SDK version: 2.14.0-321.0.dev (dev) (Thu Jul 15 08:55:11 2021 -0700) on "macos_x64"
Platform
VM and web