[fixnum] Make Int32 and Int64 final Int32 and Int64 are value types and there is no reason real instances can't be used. The upcoming `Mockito` release adds dummy values using the real `.ZERO` instances. https://github.com/dart-lang/build/pull/4961 Statically disallow sublcasses by marking the leaf classes `final`. This is a breaking change for any code outside this package that extends or implements Int32 or Int64, but this was never an intended use case.
diff --git a/pkgs/fixnum/CHANGELOG.md b/pkgs/fixnum/CHANGELOG.md index 6b89b2c..b395725 100644 --- a/pkgs/fixnum/CHANGELOG.md +++ b/pkgs/fixnum/CHANGELOG.md
@@ -6,6 +6,8 @@ * Run `dart format` with the new style. * Require Dart 3.4 * Improve `Int64` representation when compiling to native or Wasm. +* Make `Int32` and `Int64` `final` classes. They can no longer be extended or + implemented outside of this package. ## 1.1.1
diff --git a/pkgs/fixnum/lib/src/int32.dart b/pkgs/fixnum/lib/src/int32.dart index 59d9991..5a5b5e8 100644 --- a/pkgs/fixnum/lib/src/int32.dart +++ b/pkgs/fixnum/lib/src/int32.dart
@@ -10,7 +10,7 @@ /// An immutable 32-bit signed integer, in the range `[-2^31, 2^31 - 1]`. /// Arithmetic operations may overflow in order to maintain this range. -class Int32 implements IntX { +final class Int32 implements IntX { /// The maximum positive value attainable by an [Int32], namely /// 2147483647. static const Int32 MAX_VALUE = Int32._internal(0x7FFFFFFF);
diff --git a/pkgs/fixnum/lib/src/int64_emulated.dart b/pkgs/fixnum/lib/src/int64_emulated.dart index 7c10076..3af0f85 100644 --- a/pkgs/fixnum/lib/src/int64_emulated.dart +++ b/pkgs/fixnum/lib/src/int64_emulated.dart
@@ -11,7 +11,7 @@ import 'intx.dart'; import 'utilities.dart' as u; -class Int64 implements IntX { +final class Int64 implements IntX { // A 64-bit integer is represented internally as three non-negative // integers, storing the 22 low, 22 middle, and 20 high bits of the // 64-bit value. _l (low) and _m (middle) are in the range
diff --git a/pkgs/fixnum/lib/src/int64_native.dart b/pkgs/fixnum/lib/src/int64_native.dart index 25c1c9d..4a7bf2b 100644 --- a/pkgs/fixnum/lib/src/int64_native.dart +++ b/pkgs/fixnum/lib/src/int64_native.dart
@@ -10,7 +10,7 @@ /// An immutable 64-bit signed integer, in the range `[-2^63, 2^63 - 1]`. /// Arithmetic operations may overflow in order to maintain this range. -class Int64 implements IntX { +final class Int64 implements IntX { final int _i; /// The maximum positive value attainable by an [Int64], namely