Skip to content

Commit

Permalink
Merge null safety branch into master (#56)
Browse files Browse the repository at this point in the history
* migrate fixnum to null safety (flutter#55)

Primarily this is just removing a bunch of dynamic params and converting them to Object, and then removing some of the explicit tests around null args that are no longer valid statically in the test.

Note that the runtime argument errors are still present, and I left the tests in for argumentErrorTest which effectively validates the non-opted in users calling these functions still get the same behavior.

We could restore some of the other tests that I deleted to do a similar thing, if we think its worth while.
  • Loading branch information
jakemac53 authored Jun 10, 2020
1 parent 5dbf8fd commit 9b38f49
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 92 deletions.
38 changes: 26 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
language: dart

dart:
- 2.1.1
- dev
- be/raw/latest

dart_task:
- test: --platform vm
xvfb: false
- test: --platform chrome
- dartanalyzer: --fatal-warnings --fatal-infos .

matrix:
jobs:
include:
# Only validate formatting using the dev release
- dart: dev
dart_task: dartfmt
- stage: analyze_and_format
name: "Analyzer"
dart: be/raw/latest
os: linux
script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos .
- stage: analyze_and_format
name: "Format"
dart: be/raw/latest
os: linux
script: dartfmt -n --set-exit-if-changed .
- stage: test
name: "Vm Tests"
dart: be/raw/latest
os: linux
script: pub run --enable-experiment=non-nullable test -p vm
- stage: test
name: "Web Tests"
dart: be/raw/latest
os: linux
script: pub run --enable-experiment=non-nullable test -p chrome

stages:
- analyze_and_format
- test

# Only building master means that we don't run two builds for each pull request.
branches:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.0-dev

* Migrate to null safety.
* This is meant to be mostly non-breaking, for opted in users runtime errors
will be promoted to static errors. For non-opted in users the runtime
errors are still present in their original form.

## 0.10.11

* Update minimum SDK constraint to version 2.1.1.
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
enable-experiment:
- non-nullable

linter:
rules:
- avoid_function_literals_in_foreach_calls
Expand Down
36 changes: 18 additions & 18 deletions lib/src/int32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Int32 implements IntX {

// Returns the [int] representation of the specified value. Throws
// [ArgumentError] for non-integer arguments.
int _toInt(val) {
int _toInt(Object val) {
if (val is Int32) {
return val._i;
} else if (val is int) {
Expand All @@ -146,15 +146,15 @@ class Int32 implements IntX {
// Int32 % Int64 => Int32

@override
IntX operator +(other) {
IntX operator +(Object other) {
if (other is Int64) {
return toInt64() + other;
}
return Int32(_i + _toInt(other));
}

@override
IntX operator -(other) {
IntX operator -(Object other) {
if (other is Int64) {
return toInt64() - other;
}
Expand All @@ -165,7 +165,7 @@ class Int32 implements IntX {
Int32 operator -() => Int32(-_i);

@override
IntX operator *(other) {
IntX operator *(Object other) {
if (other is Int64) {
return toInt64() * other;
}
Expand All @@ -174,7 +174,7 @@ class Int32 implements IntX {
}

@override
Int32 operator %(other) {
Int32 operator %(Object other) {
if (other is Int64) {
// Result will be Int32
return (toInt64() % other).toInt32();
Expand All @@ -183,15 +183,15 @@ class Int32 implements IntX {
}

@override
Int32 operator ~/(other) {
Int32 operator ~/(Object other) {
if (other is Int64) {
return (toInt64() ~/ other).toInt32();
}
return Int32(_i ~/ _toInt(other));
}

@override
Int32 remainder(other) {
Int32 remainder(Object other) {
if (other is Int64) {
var t = toInt64();
return (t - (t ~/ other) * other).toInt32();
Expand All @@ -200,23 +200,23 @@ class Int32 implements IntX {
}

@override
Int32 operator &(other) {
Int32 operator &(Object other) {
if (other is Int64) {
return (toInt64() & other).toInt32();
}
return Int32(_i & _toInt(other));
}

@override
Int32 operator |(other) {
Int32 operator |(Object other) {
if (other is Int64) {
return (toInt64() | other).toInt32();
}
return Int32(_i | _toInt(other));
}

@override
Int32 operator ^(other) {
Int32 operator ^(Object other) {
if (other is Int64) {
return (toInt64() ^ other).toInt32();
}
Expand Down Expand Up @@ -274,7 +274,7 @@ class Int32 implements IntX {
/// Returns [:true:] if this [Int32] has the same numeric value as the
/// given object. The argument may be an [int] or an [IntX].
@override
bool operator ==(other) {
bool operator ==(Object other) {
if (other is Int32) {
return _i == other._i;
} else if (other is Int64) {
Expand All @@ -286,39 +286,39 @@ class Int32 implements IntX {
}

@override
int compareTo(other) {
int compareTo(Object other) {
if (other is Int64) {
return toInt64().compareTo(other);
}
return _i.compareTo(_toInt(other));
}

@override
bool operator <(other) {
bool operator <(Object other) {
if (other is Int64) {
return toInt64() < other;
}
return _i < _toInt(other);
}

@override
bool operator <=(other) {
bool operator <=(Object other) {
if (other is Int64) {
return toInt64() <= other;
}
return _i <= _toInt(other);
}

@override
bool operator >(other) {
bool operator >(Object other) {
if (other is Int64) {
return toInt64() > other;
}
return _i > _toInt(other);
}

@override
bool operator >=(other) {
bool operator >=(Object other) {
if (other is Int64) {
return toInt64() >= other;
}
Expand Down Expand Up @@ -353,7 +353,7 @@ class Int32 implements IntX {
Int32 abs() => _i < 0 ? Int32(-_i) : this;

@override
Int32 clamp(lowerLimit, upperLimit) {
Int32 clamp(Object lowerLimit, Object upperLimit) {
if (this < lowerLimit) {
if (lowerLimit is IntX) return lowerLimit.toInt32();
if (lowerLimit is int) return Int32(lowerLimit);
Expand Down Expand Up @@ -386,7 +386,7 @@ class Int32 implements IntX {

@override
List<int> toBytes() {
var result = List<int>(4);
var result = List<int>.filled(4, 0);
result[0] = _i & 0xff;
result[1] = (_i >> 8) & 0xff;
result[2] = (_i >> 16) & 0xff;
Expand Down
38 changes: 19 additions & 19 deletions lib/src/int64.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Int64 implements IntX {
}

@override
Int64 operator +(other) {
Int64 operator +(Object other) {
Int64 o = _promote(other);
int sum0 = _l + o._l;
int sum1 = _m + o._m + (sum0 >> _BITS);
Expand All @@ -207,7 +207,7 @@ class Int64 implements IntX {
}

@override
Int64 operator -(other) {
Int64 operator -(Object other) {
Int64 o = _promote(other);
return _sub(_l, _m, _h, o._l, o._m, o._h);
}
Expand All @@ -216,7 +216,7 @@ class Int64 implements IntX {
Int64 operator -() => _negate(_l, _m, _h);

@override
Int64 operator *(other) {
Int64 operator *(Object other) {
Int64 o = _promote(other);

// Grab 13-bit chunks.
Expand Down Expand Up @@ -298,16 +298,16 @@ class Int64 implements IntX {
}

@override
Int64 operator %(other) => _divide(this, other, _RETURN_MOD);
Int64 operator %(Object other) => _divide(this, other, _RETURN_MOD);

@override
Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV);
Int64 operator ~/(Object other) => _divide(this, other, _RETURN_DIV);

@override
Int64 remainder(other) => _divide(this, other, _RETURN_REM);
Int64 remainder(Object other) => _divide(this, other, _RETURN_REM);

@override
Int64 operator &(other) {
Int64 operator &(Object other) {
Int64 o = _promote(other);
int a0 = _l & o._l;
int a1 = _m & o._m;
Expand All @@ -316,7 +316,7 @@ class Int64 implements IntX {
}

@override
Int64 operator |(other) {
Int64 operator |(Object other) {
Int64 o = _promote(other);
int a0 = _l | o._l;
int a1 = _m | o._m;
Expand All @@ -325,7 +325,7 @@ class Int64 implements IntX {
}

@override
Int64 operator ^(other) {
Int64 operator ^(Object other) {
Int64 o = _promote(other);
int a0 = _l ^ o._l;
int a1 = _m ^ o._m;
Expand Down Expand Up @@ -442,8 +442,8 @@ class Int64 implements IntX {
/// Returns [:true:] if this [Int64] has the same numeric value as the
/// given object. The argument may be an [int] or an [IntX].
@override
bool operator ==(other) {
Int64 o;
bool operator ==(Object other) {
Int64? o;
if (other is Int64) {
o = other;
} else if (other is int) {
Expand All @@ -462,9 +462,9 @@ class Int64 implements IntX {
}

@override
int compareTo(other) => _compareTo(other);
int compareTo(Object other) => _compareTo(other);

int _compareTo(other) {
int _compareTo(Object other) {
Int64 o = _promote(other);
int signa = _h >> (_BITS2 - 1);
int signb = o._h >> (_BITS2 - 1);
Expand All @@ -490,16 +490,16 @@ class Int64 implements IntX {
}

@override
bool operator <(other) => _compareTo(other) < 0;
bool operator <(Object other) => _compareTo(other) < 0;

@override
bool operator <=(other) => _compareTo(other) <= 0;
bool operator <=(Object other) => _compareTo(other) <= 0;

@override
bool operator >(other) => _compareTo(other) > 0;
bool operator >(Object other) => _compareTo(other) > 0;

@override
bool operator >=(other) => _compareTo(other) >= 0;
bool operator >=(Object other) => _compareTo(other) >= 0;

@override
bool get isEven => (_l & 0x1) == 0;
Expand Down Expand Up @@ -549,7 +549,7 @@ class Int64 implements IntX {
}

@override
Int64 clamp(lowerLimit, upperLimit) {
Int64 clamp(Object lowerLimit, Object upperLimit) {
Int64 lower = _promote(lowerLimit);
Int64 upper = _promote(upperLimit);
if (this < lower) return lower;
Expand Down Expand Up @@ -631,7 +631,7 @@ class Int64 implements IntX {

@override
List<int> toBytes() {
List<int> result = List<int>(8);
var result = List<int>.filled(8, 0);
result[0] = _l & 0xff;
result[1] = (_l >> 8) & 0xff;
result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f);
Expand Down
Loading

0 comments on commit 9b38f49

Please sign in to comment.