Skip to content

Commit 7270622

Browse files
committed
Change the return type.
1 parent 661ea1f commit 7270622

File tree

9 files changed

+26
-15
lines changed

9 files changed

+26
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
1010
[file an issue]: https://github.com/matanlurey/binary.dart/issues
1111

12+
## 4.0.0-alpha+6
13+
14+
- Just kidding, `checkRange` will return `{{Int}}` if no error is thrown.
15+
1216
## 4.0.0-alpha+5
1317

1418
- `<Int>.checkRange` returns the `int` if no error was thrown (instead of

lib/src/int16.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ extension type const Int16._(int _) implements int {
9898
static bool isValid(int v) => v >= minInt && v <= maxInt;
9999

100100
/// Returns [value] if its in a valid range for Int16.
101-
static int checkRange(int value) {
102-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
static Int16 checkRange(int value) {
102+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
103+
return Int16.fromUnchecked(value);
103104
}
104105

105106
/// Defines [v] as A signed 16-bit integer, wrapping if necessary.

lib/src/int32.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ extension type const Int32._(int _) implements int {
9898
static bool isValid(int v) => v >= minInt && v <= maxInt;
9999

100100
/// Returns [value] if its in a valid range for Int32.
101-
static int checkRange(int value) {
102-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
static Int32 checkRange(int value) {
102+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
103+
return Int32.fromUnchecked(value);
103104
}
104105

105106
/// Defines [v] as A signed 32-bit integer, wrapping if necessary.

lib/src/int8.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ extension type const Int8._(int _) implements int {
9696
static bool isValid(int v) => v >= minInt && v <= maxInt;
9797

9898
/// Returns [value] if its in a valid range for Int8.
99-
static int checkRange(int value) {
100-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
99+
static Int8 checkRange(int value) {
100+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
return Int8.fromUnchecked(value);
101102
}
102103

103104
/// Defines [v] as A signed 8-bit integer, wrapping if necessary.

lib/src/uint16.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ extension type const Uint16._(int _) implements int {
9898
static bool isValid(int v) => v >= minInt && v <= maxInt;
9999

100100
/// Returns [value] if its in a valid range for Uint16.
101-
static int checkRange(int value) {
102-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
static Uint16 checkRange(int value) {
102+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
103+
return Uint16.fromUnchecked(value);
103104
}
104105

105106
/// Defines [v] as An unsigned 16-bit integer, wrapping if necessary.

lib/src/uint32.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ extension type const Uint32._(int _) implements int {
9898
static bool isValid(int v) => v >= minInt && v <= maxInt;
9999

100100
/// Returns [value] if its in a valid range for Uint32.
101-
static int checkRange(int value) {
102-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
static Uint32 checkRange(int value) {
102+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
103+
return Uint32.fromUnchecked(value);
103104
}
104105

105106
/// Defines [v] as An unsigned 32-bit integer, wrapping if necessary.

lib/src/uint8.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ extension type const Uint8._(int _) implements int {
9696
static bool isValid(int v) => v >= minInt && v <= maxInt;
9797

9898
/// Returns [value] if its in a valid range for Uint8.
99-
static int checkRange(int value) {
100-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
99+
static Uint8 checkRange(int value) {
100+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
return Uint8.fromUnchecked(value);
101102
}
102103

103104
/// Defines [v] as An unsigned 8-bit integer, wrapping if necessary.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name: binary
44
description: Utilities for accessing binary data and bit manipulation in Dart and Flutter
5-
version: 4.0.0-alpha+5
5+
version: 4.0.0-alpha+6
66

77
environment:
88
# Required for https://github.com/dart-lang/sdk/issues/55135

tool/template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ extension type const {{NAME}}._(int _) implements int {
9696
static bool isValid(int v) => v >= minInt && v <= maxInt;
9797

9898
/// Returns [value] if its in a valid range for {{NAME}}.
99-
static int checkRange(int value) {
100-
return RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
99+
static {{NAME}} checkRange(int value) {
100+
RangeError.checkValueInInterval(value, minInt, maxInt, 'value');
101+
return {{NAME}}.fromUnchecked(value);
101102
}
102103

103104
/// Defines [v] as {{DESCRIPTION}}, wrapping if necessary.

0 commit comments

Comments
 (0)