This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 1d1417cb1 fix(dart): added <<< for correct logical right shift
semantics in uint (#3607)
1d1417cb1 is described below
commit 1d1417cb1457b6c04207cc1c26402b8c591f2a79
Author: Ayush Kumar <[email protected]>
AuthorDate: Fri Apr 24 10:08:11 2026 +0530
fix(dart): added <<< for correct logical right shift semantics in uint
(#3607)
## Why?
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.
## What does this PR do?
Implement the operator >>> (logical right shift) for all unsigned
integer wrappers to expose a proper logical shift API.
## Related issues
#3606
<!--
Is there any related issue? If this PR closes them you say say
fix/closes:
- #xxxx0
- #xxxx1
- Fixes #xxxx2
-->
## AI Contribution Checklist
<!-- Full requirements and disclosure template:
https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs
-->
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence of the final clean AI review results
from both fresh reviewers on the current PR diff or current HEAD after
the latest code changes.
<!-- If substantial AI assistance = `yes`, paste the completed checklist
and disclosure block here, including the final ai_review summary and
screenshot evidence from both fresh reviewers on the current PR diff or
current HEAD after the latest code changes. -->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fory/issues/new/choose) describing the
need to do so and update the document if necessary.
Delete section if not applicable.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
dart/packages/fory/lib/src/types/uint16.dart | 4 +++-
dart/packages/fory/lib/src/types/uint32.dart | 4 +++-
dart/packages/fory/lib/src/types/uint8.dart | 4 +++-
dart/packages/fory/test/numeric_wrapper_test.dart | 7 +++++++
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dart/packages/fory/lib/src/types/uint16.dart
b/dart/packages/fory/lib/src/types/uint16.dart
index 1a92db2e6..47bd69425 100644
--- a/dart/packages/fory/lib/src/types/uint16.dart
+++ b/dart/packages/fory/lib/src/types/uint16.dart
@@ -101,7 +101,9 @@ final class Uint16 implements Comparable<Uint16> {
Uint16 operator <<(int shift) => Uint16(value << shift);
- Uint16 operator >>(int shift) => Uint16(value >> shift);
+ Uint16 operator >>(int shift) => Uint16(value >>> shift);
+
+ Uint16 operator >>>(int shift) => Uint16(value >>> shift);
bool operator <(Object other) => switch (other) {
int otherValue => value < otherValue,
diff --git a/dart/packages/fory/lib/src/types/uint32.dart
b/dart/packages/fory/lib/src/types/uint32.dart
index b8b81c62f..7da4f5f31 100644
--- a/dart/packages/fory/lib/src/types/uint32.dart
+++ b/dart/packages/fory/lib/src/types/uint32.dart
@@ -101,7 +101,9 @@ final class Uint32 implements Comparable<Uint32> {
Uint32 operator <<(int shift) => Uint32(value << shift);
- Uint32 operator >>(int shift) => Uint32(value >> shift);
+ Uint32 operator >>(int shift) => Uint32(value >>> shift);
+
+ Uint32 operator >>>(int shift) => Uint32(value >>> shift);
bool operator <(Object other) => switch (other) {
int otherValue => value < otherValue,
diff --git a/dart/packages/fory/lib/src/types/uint8.dart
b/dart/packages/fory/lib/src/types/uint8.dart
index ee88c0540..bde29e661 100644
--- a/dart/packages/fory/lib/src/types/uint8.dart
+++ b/dart/packages/fory/lib/src/types/uint8.dart
@@ -101,7 +101,9 @@ final class Uint8 implements Comparable<Uint8> {
Uint8 operator <<(int shift) => Uint8(value << shift);
- Uint8 operator >>(int shift) => Uint8(value >> shift);
+ Uint8 operator >>(int shift) => Uint8(value >>> shift);
+
+ Uint8 operator >>>(int shift) => Uint8(value >>> shift);
bool operator <(Object other) => switch (other) {
int otherValue => value < otherValue,
diff --git a/dart/packages/fory/test/numeric_wrapper_test.dart
b/dart/packages/fory/test/numeric_wrapper_test.dart
index 969919cdf..f5f0436c8 100644
--- a/dart/packages/fory/test/numeric_wrapper_test.dart
+++ b/dart/packages/fory/test/numeric_wrapper_test.dart
@@ -172,15 +172,22 @@ void main() {
expect(Uint8(0xff) + 1, equals(Uint8(0)));
expect(Uint8(0) - 1, equals(Uint8(0xff)));
expect(Uint8(0xf0) >> 4, equals(Uint8(0x0f)));
+ expect(Uint8(0xf0) >>> 4, equals(Uint8(0x0f)));
+ expect(Uint8(0xff) >> 1, equals(Uint8(0x7f)));
+ expect(Uint8(0xff) >>> 1, equals(Uint8(0x7f)));
expect(-Uint8(1), equals(Uint8(0xff)));
expect(Uint16(0xffff) + 1, equals(Uint16(0)));
expect(Uint16(0) - 1, equals(Uint16(0xffff)));
+ expect(Uint16(0xffff) >> 1, equals(Uint16(0x7fff)));
+ expect(Uint16(0xffff) >>> 1, equals(Uint16(0x7fff)));
expect(Uint32(0xffffffff) + 1, equals(Uint32(0)));
expect(Uint32(0) - 1, equals(Uint32(0xffffffff)));
expect(
Uint32(0xf0f0f0f0) & Uint32(0x0ff00ff0), equals(Uint32(0x00f000f0)));
+ expect(Uint32(0xffffffff) >> 1, equals(Uint32(0x7fffffff)));
+ expect(Uint32(0xffffffff) >>> 1, equals(Uint32(0x7fffffff)));
expect(_u64Hex('ffffffffffffffff') + 1, equals(Uint64(0)));
expect(Uint64(0) - 1, equals(_u64Hex('ffffffffffffffff')));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]