From f378dabd3a42410ed650a772eadf0b322872c3ba Mon Sep 17 00:00:00 2001 From: ayush00git Date: Wed, 22 Apr 2026 22:10:16 +0530 Subject: [PATCH 1/2] fix(dart): added <<< for correct logical right shift semantics in uint --- dart/packages/fory/lib/src/types/uint16.dart | 4 +++- dart/packages/fory/lib/src/types/uint32.dart | 4 +++- dart/packages/fory/lib/src/types/uint64.dart | 4 +++- dart/packages/fory/lib/src/types/uint8.dart | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dart/packages/fory/lib/src/types/uint16.dart b/dart/packages/fory/lib/src/types/uint16.dart index 1a92db2e65..47bd694257 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 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 b8b81c62fa..7da4f5f314 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 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/uint64.dart b/dart/packages/fory/lib/src/types/uint64.dart index 1c335e84f2..32d7331598 100644 --- a/dart/packages/fory/lib/src/types/uint64.dart +++ b/dart/packages/fory/lib/src/types/uint64.dart @@ -103,7 +103,9 @@ final class Uint64 implements Comparable { Uint64 operator <<(int shift) => Uint64(value << shift); - Uint64 operator >>(int shift) => Uint64(value >> shift); + Uint64 operator >>(int shift) => Uint64(value >>> shift); + + Uint64 operator >>>(int shift) => Uint64(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 ee88c05402..bde29e6610 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 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, From 775598e5e7266fbeea8be8684989590e280e5121 Mon Sep 17 00:00:00 2001 From: ayush00git Date: Wed, 22 Apr 2026 22:11:37 +0530 Subject: [PATCH 2/2] feat: added test coverings --- dart/packages/fory/test/numeric_wrapper_test.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dart/packages/fory/test/numeric_wrapper_test.dart b/dart/packages/fory/test/numeric_wrapper_test.dart index a944761f87..069619189f 100644 --- a/dart/packages/fory/test/numeric_wrapper_test.dart +++ b/dart/packages/fory/test/numeric_wrapper_test.dart @@ -133,20 +133,31 @@ 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(Uint64(0xffffffffffffffff) + 1, equals(Uint64(0))); expect(Uint64(0) - 1, equals(Uint64(0xffffffffffffffff))); expect( Uint64(0x123456789abcdef0) >> 4, equals(Uint64(0x0123456789abcdef))); + expect( + Uint64(0xffffffffffffffff) >> 1, equals(Uint64(0x7fffffffffffffff))); + expect( + Uint64(0xffffffffffffffff) >>> 1, equals(Uint64(0x7fffffffffffffff))); expect(Uint64(0xff).toInt(), equals(0xff)); });