Skip to content

Commit 9b38f49

Browse files
authored
Merge null safety branch into master (#56)
* 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.
1 parent 5dbf8fd commit 9b38f49

9 files changed

Lines changed: 186 additions & 92 deletions

File tree

.travis.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
language: dart
22

33
dart:
4-
- 2.1.1
5-
- dev
4+
- be/raw/latest
65

7-
dart_task:
8-
- test: --platform vm
9-
xvfb: false
10-
- test: --platform chrome
11-
- dartanalyzer: --fatal-warnings --fatal-infos .
12-
13-
matrix:
6+
jobs:
147
include:
15-
# Only validate formatting using the dev release
16-
- dart: dev
17-
dart_task: dartfmt
8+
- stage: analyze_and_format
9+
name: "Analyzer"
10+
dart: be/raw/latest
11+
os: linux
12+
script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos .
13+
- stage: analyze_and_format
14+
name: "Format"
15+
dart: be/raw/latest
16+
os: linux
17+
script: dartfmt -n --set-exit-if-changed .
18+
- stage: test
19+
name: "Vm Tests"
20+
dart: be/raw/latest
21+
os: linux
22+
script: pub run --enable-experiment=non-nullable test -p vm
23+
- stage: test
24+
name: "Web Tests"
25+
dart: be/raw/latest
26+
os: linux
27+
script: pub run --enable-experiment=non-nullable test -p chrome
28+
29+
stages:
30+
- analyze_and_format
31+
- test
1832

1933
# Only building master means that we don't run two builds for each pull request.
2034
branches:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.0.0-dev
2+
3+
* Migrate to null safety.
4+
* This is meant to be mostly non-breaking, for opted in users runtime errors
5+
will be promoted to static errors. For non-opted in users the runtime
6+
errors are still present in their original form.
7+
18
## 0.10.11
29

310
* Update minimum SDK constraint to version 2.1.1.

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ include: package:pedantic/analysis_options.yaml
22
analyzer:
33
strong-mode:
44
implicit-casts: false
5+
enable-experiment:
6+
- non-nullable
7+
58
linter:
69
rules:
710
- avoid_function_literals_in_foreach_calls

lib/src/int32.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Int32 implements IntX {
122122

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

148148
@override
149-
IntX operator +(other) {
149+
IntX operator +(Object other) {
150150
if (other is Int64) {
151151
return toInt64() + other;
152152
}
153153
return Int32(_i + _toInt(other));
154154
}
155155

156156
@override
157-
IntX operator -(other) {
157+
IntX operator -(Object other) {
158158
if (other is Int64) {
159159
return toInt64() - other;
160160
}
@@ -165,7 +165,7 @@ class Int32 implements IntX {
165165
Int32 operator -() => Int32(-_i);
166166

167167
@override
168-
IntX operator *(other) {
168+
IntX operator *(Object other) {
169169
if (other is Int64) {
170170
return toInt64() * other;
171171
}
@@ -174,7 +174,7 @@ class Int32 implements IntX {
174174
}
175175

176176
@override
177-
Int32 operator %(other) {
177+
Int32 operator %(Object other) {
178178
if (other is Int64) {
179179
// Result will be Int32
180180
return (toInt64() % other).toInt32();
@@ -183,15 +183,15 @@ class Int32 implements IntX {
183183
}
184184

185185
@override
186-
Int32 operator ~/(other) {
186+
Int32 operator ~/(Object other) {
187187
if (other is Int64) {
188188
return (toInt64() ~/ other).toInt32();
189189
}
190190
return Int32(_i ~/ _toInt(other));
191191
}
192192

193193
@override
194-
Int32 remainder(other) {
194+
Int32 remainder(Object other) {
195195
if (other is Int64) {
196196
var t = toInt64();
197197
return (t - (t ~/ other) * other).toInt32();
@@ -200,23 +200,23 @@ class Int32 implements IntX {
200200
}
201201

202202
@override
203-
Int32 operator &(other) {
203+
Int32 operator &(Object other) {
204204
if (other is Int64) {
205205
return (toInt64() & other).toInt32();
206206
}
207207
return Int32(_i & _toInt(other));
208208
}
209209

210210
@override
211-
Int32 operator |(other) {
211+
Int32 operator |(Object other) {
212212
if (other is Int64) {
213213
return (toInt64() | other).toInt32();
214214
}
215215
return Int32(_i | _toInt(other));
216216
}
217217

218218
@override
219-
Int32 operator ^(other) {
219+
Int32 operator ^(Object other) {
220220
if (other is Int64) {
221221
return (toInt64() ^ other).toInt32();
222222
}
@@ -274,7 +274,7 @@ class Int32 implements IntX {
274274
/// Returns [:true:] if this [Int32] has the same numeric value as the
275275
/// given object. The argument may be an [int] or an [IntX].
276276
@override
277-
bool operator ==(other) {
277+
bool operator ==(Object other) {
278278
if (other is Int32) {
279279
return _i == other._i;
280280
} else if (other is Int64) {
@@ -286,39 +286,39 @@ class Int32 implements IntX {
286286
}
287287

288288
@override
289-
int compareTo(other) {
289+
int compareTo(Object other) {
290290
if (other is Int64) {
291291
return toInt64().compareTo(other);
292292
}
293293
return _i.compareTo(_toInt(other));
294294
}
295295

296296
@override
297-
bool operator <(other) {
297+
bool operator <(Object other) {
298298
if (other is Int64) {
299299
return toInt64() < other;
300300
}
301301
return _i < _toInt(other);
302302
}
303303

304304
@override
305-
bool operator <=(other) {
305+
bool operator <=(Object other) {
306306
if (other is Int64) {
307307
return toInt64() <= other;
308308
}
309309
return _i <= _toInt(other);
310310
}
311311

312312
@override
313-
bool operator >(other) {
313+
bool operator >(Object other) {
314314
if (other is Int64) {
315315
return toInt64() > other;
316316
}
317317
return _i > _toInt(other);
318318
}
319319

320320
@override
321-
bool operator >=(other) {
321+
bool operator >=(Object other) {
322322
if (other is Int64) {
323323
return toInt64() >= other;
324324
}
@@ -353,7 +353,7 @@ class Int32 implements IntX {
353353
Int32 abs() => _i < 0 ? Int32(-_i) : this;
354354

355355
@override
356-
Int32 clamp(lowerLimit, upperLimit) {
356+
Int32 clamp(Object lowerLimit, Object upperLimit) {
357357
if (this < lowerLimit) {
358358
if (lowerLimit is IntX) return lowerLimit.toInt32();
359359
if (lowerLimit is int) return Int32(lowerLimit);
@@ -386,7 +386,7 @@ class Int32 implements IntX {
386386

387387
@override
388388
List<int> toBytes() {
389-
var result = List<int>(4);
389+
var result = List<int>.filled(4, 0);
390390
result[0] = _i & 0xff;
391391
result[1] = (_i >> 8) & 0xff;
392392
result[2] = (_i >> 16) & 0xff;

lib/src/int64.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Int64 implements IntX {
198198
}
199199

200200
@override
201-
Int64 operator +(other) {
201+
Int64 operator +(Object other) {
202202
Int64 o = _promote(other);
203203
int sum0 = _l + o._l;
204204
int sum1 = _m + o._m + (sum0 >> _BITS);
@@ -207,7 +207,7 @@ class Int64 implements IntX {
207207
}
208208

209209
@override
210-
Int64 operator -(other) {
210+
Int64 operator -(Object other) {
211211
Int64 o = _promote(other);
212212
return _sub(_l, _m, _h, o._l, o._m, o._h);
213213
}
@@ -216,7 +216,7 @@ class Int64 implements IntX {
216216
Int64 operator -() => _negate(_l, _m, _h);
217217

218218
@override
219-
Int64 operator *(other) {
219+
Int64 operator *(Object other) {
220220
Int64 o = _promote(other);
221221

222222
// Grab 13-bit chunks.
@@ -298,16 +298,16 @@ class Int64 implements IntX {
298298
}
299299

300300
@override
301-
Int64 operator %(other) => _divide(this, other, _RETURN_MOD);
301+
Int64 operator %(Object other) => _divide(this, other, _RETURN_MOD);
302302

303303
@override
304-
Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV);
304+
Int64 operator ~/(Object other) => _divide(this, other, _RETURN_DIV);
305305

306306
@override
307-
Int64 remainder(other) => _divide(this, other, _RETURN_REM);
307+
Int64 remainder(Object other) => _divide(this, other, _RETURN_REM);
308308

309309
@override
310-
Int64 operator &(other) {
310+
Int64 operator &(Object other) {
311311
Int64 o = _promote(other);
312312
int a0 = _l & o._l;
313313
int a1 = _m & o._m;
@@ -316,7 +316,7 @@ class Int64 implements IntX {
316316
}
317317

318318
@override
319-
Int64 operator |(other) {
319+
Int64 operator |(Object other) {
320320
Int64 o = _promote(other);
321321
int a0 = _l | o._l;
322322
int a1 = _m | o._m;
@@ -325,7 +325,7 @@ class Int64 implements IntX {
325325
}
326326

327327
@override
328-
Int64 operator ^(other) {
328+
Int64 operator ^(Object other) {
329329
Int64 o = _promote(other);
330330
int a0 = _l ^ o._l;
331331
int a1 = _m ^ o._m;
@@ -442,8 +442,8 @@ class Int64 implements IntX {
442442
/// Returns [:true:] if this [Int64] has the same numeric value as the
443443
/// given object. The argument may be an [int] or an [IntX].
444444
@override
445-
bool operator ==(other) {
446-
Int64 o;
445+
bool operator ==(Object other) {
446+
Int64? o;
447447
if (other is Int64) {
448448
o = other;
449449
} else if (other is int) {
@@ -462,9 +462,9 @@ class Int64 implements IntX {
462462
}
463463

464464
@override
465-
int compareTo(other) => _compareTo(other);
465+
int compareTo(Object other) => _compareTo(other);
466466

467-
int _compareTo(other) {
467+
int _compareTo(Object other) {
468468
Int64 o = _promote(other);
469469
int signa = _h >> (_BITS2 - 1);
470470
int signb = o._h >> (_BITS2 - 1);
@@ -490,16 +490,16 @@ class Int64 implements IntX {
490490
}
491491

492492
@override
493-
bool operator <(other) => _compareTo(other) < 0;
493+
bool operator <(Object other) => _compareTo(other) < 0;
494494

495495
@override
496-
bool operator <=(other) => _compareTo(other) <= 0;
496+
bool operator <=(Object other) => _compareTo(other) <= 0;
497497

498498
@override
499-
bool operator >(other) => _compareTo(other) > 0;
499+
bool operator >(Object other) => _compareTo(other) > 0;
500500

501501
@override
502-
bool operator >=(other) => _compareTo(other) >= 0;
502+
bool operator >=(Object other) => _compareTo(other) >= 0;
503503

504504
@override
505505
bool get isEven => (_l & 0x1) == 0;
@@ -549,7 +549,7 @@ class Int64 implements IntX {
549549
}
550550

551551
@override
552-
Int64 clamp(lowerLimit, upperLimit) {
552+
Int64 clamp(Object lowerLimit, Object upperLimit) {
553553
Int64 lower = _promote(lowerLimit);
554554
Int64 upper = _promote(upperLimit);
555555
if (this < lower) return lower;
@@ -631,7 +631,7 @@ class Int64 implements IntX {
631631

632632
@override
633633
List<int> toBytes() {
634-
List<int> result = List<int>(8);
634+
var result = List<int>.filled(8, 0);
635635
result[0] = _l & 0xff;
636636
result[1] = (_l >> 8) & 0xff;
637637
result[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f);

0 commit comments

Comments
 (0)