typed_data
typed_data copied to clipboard
Int16List performs implicit conversions when assigning list elements
Some of the Dart code I'm working with reads unsigned 16 bit data from a Wav file into an IntList... and I noticed something odd going on.
The following test fails with Expected: <65508> Actual: <-28>:
test('store_int_in_int16list', () {
int myInt = 65508;
Int16List int16 = Int16List(1);
int16[0] = myInt;
expect(int16[0], 65508);
});
I noted Dart doesn't let you assign int to Int16. The following code gives a compiler error and politely asks that the int be cast to Int16:
int myInt = 65508;
Int16 int16 = myInt;
So I suspect the assignment of an int to an element in an Int16List shouldn't be allowed either. I'm not sure if it's easy/possible to catch that though.