ayush00git opened a new issue, #3606: URL: https://github.com/apache/fory/issues/3606
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues. ### Version 0.17.0 ### Component(s) Other ### Minimal reproduce step **Steps to Reproduce** 1. Run the following Dart script on the Native Dart VM: ```dart import 'package:fory/fory.dart'; // Adjust to your actual import path void main() { // Create a Uint64 with the highest bit set final maxUint64 = Uint64(0xFFFFFFFFFFFFFFFF); // Evaluates to -1 internally // Perform a right shift final shifted = maxUint64 >> 1; print('Original: \$maxUint64'); print('Shifted : \$shifted'); // The expected result of a logical right shift on max Uint64 final expected = Uint64(0x7FFFFFFFFFFFFFFF); print('Expected: \$expected'); if (shifted != expected) { print('❌ Bug reproduced: Uint64 right shift is sign-extending!'); } else { print('✅ Working as expected.'); } } ### What did you expect to see? Expected Behavior The right shift on an unsigned 64-bit integer should perform a logical right shift, yielding 0x7FFFFFFFFFFFFFFF for Uint64(0xFFFFFFFFFFFFFFFF) >> 1 ### What did you see instead? `Uint64(0xFFFFFFFFFFFFFFFF) >> 1` evaluates to `-1` (`0xFFFFFFFFFFFFFFFF`), instead of the expected unsigned right shift `0x7FFFFFFFFFFFFFFF`. ### Anything Else? **Description** The unsigned integer wrapper classes in Fory's Dart implementation (specifically `Uint64`) implement the right shift `>>` operator by delegating directly to Dart's native `int.operator >>`. In Dart, `>>` performs an arithmetic (sign-extending) right shift. While `toUnsigned(32)` creates a non-negative number for `Uint32` (meaning `>>` and `>>>` behave identically), `toUnsigned(64)` produces a signed 64-bit integer on the Native Dart VM. If the highest bit (the 63rd bit) is set, the value is evaluated as a negative number. This causes data corruption for `Uint64` shift operations for values `>= 2^63`. For example, `Uint64(0xFFFFFFFFFFFFFFFF) >> 1` evaluates to `-1` (`0xFFFFFFFFFFFFFFFF`), instead of the expected unsigned right shift `0x7FFFFFFFFFFFFFFF`. ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
