Closed
Description
BigInt is backed by TypedData (Uint32List), which is converted to ExternalTypedData when sent between isolates if it exceeds certain size (kExternalizeTypedDataThreshold in raw_object_snapshot.cc).
However, BigInt intrinsics do no account for this and handle only regular TypedData. This results in incorrect behavior of arithmetic operations after receiving such BigInt.
Test:
import 'dart:io';
import 'dart:isolate';
import "package:expect/expect.dart";
const int kValue = 12345678;
const int kShift = 8192 * 8;
void verify(BigInt x) {
BigInt y = x >> kShift;
Expect.equals("$kValue", "$y");
}
void main() {
BigInt big = BigInt.from(kValue) << kShift;
verify(big);
final rp = new ReceivePort();
rp.listen((dynamic data) {
BigInt received = data as BigInt;
verify(received);
BigInt x = received + BigInt.one - BigInt.one;
verify(x);
print("ok");
exit(0);
});
rp.sendPort.send(big);
}
This issue is somewhat similar to flutter/flutter#22796, as it is also caused by morphing TypedData to ExternalTypedData when it is sent between isolates.