Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d6762df

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM/libraries] Fix more analyzer errors in patch files.
Change-Id: I51c4aaa38a3eb01f2a6914a0e4b5d25f103fa797 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132449 Commit-Queue: Siva Annamalai <asiva@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
1 parent 582727a commit d6762df

17 files changed

+183
-171
lines changed

sdk_nnbd/lib/_internal/vm/lib/array.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class _FixedSizeArrayIterator<E> implements Iterator<E> {
241241
final List<E> _array;
242242
final int _length; // Cache array length for faster access.
243243
int _index;
244-
E _current;
244+
E? _current;
245245

246246
_FixedSizeArrayIterator(List<E> array)
247247
: _array = array,
@@ -250,7 +250,7 @@ class _FixedSizeArrayIterator<E> implements Iterator<E> {
250250
assert(array is _List<E> || array is _ImmutableList<E>);
251251
}
252252

253-
E get current => _current;
253+
E get current => _current as E;
254254

255255
@pragma("vm:prefer-inline")
256256
bool moveNext() {

sdk_nnbd/lib/_internal/vm/lib/async_patch.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class _AsyncStarStreamController<T> {
140140
bool onListenReceived = false;
141141
bool isScheduled = false;
142142
bool isSuspendedAtYield = false;
143-
_Future cancellationFuture = null;
143+
_Future? cancellationFuture = null;
144144

145145
Stream<T> get stream {
146146
final Stream<T> local = controller.stream;
@@ -231,11 +231,11 @@ class _AsyncStarStreamController<T> {
231231
controller.close();
232232
}
233233

234-
_AsyncStarStreamController(this.asyncStarBody) {
235-
controller = new StreamController(
236-
onListen: this.onListen,
237-
onResume: this.onResume,
238-
onCancel: this.onCancel);
234+
_AsyncStarStreamController(this.asyncStarBody)
235+
: controller = new StreamController() {
236+
controller.onListen = this.onListen;
237+
controller.onResume = this.onResume;
238+
controller.onCancel = this.onCancel;
239239
}
240240

241241
onListen() {
@@ -273,17 +273,17 @@ void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow";
273273
@patch
274274
class _Future<T> {
275275
/// The closure implementing the async[*]-body that is `await`ing this future.
276-
Function _awaiter;
276+
Function? _awaiter;
277277
}
278278

279279
@patch
280280
class _StreamImpl<T> {
281281
/// The closure implementing the async[*]-body that is `await`ing this future.
282-
Function _awaiter;
282+
Function? _awaiter;
283283

284284
/// The closure implementing the async-generator body that is creating events
285285
/// for this stream.
286-
Function _generator;
286+
Function? _generator;
287287
}
288288

289289
@pragma("vm:entry-point", "call")

sdk_nnbd/lib/_internal/vm/lib/collection_patch.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class _HashMap<K, V> extends MapBase<K, V> implements HashMap<K, V> {
186186
}
187187

188188
void clear() {
189-
_buckets = new List(_INITIAL_CAPACITY);
189+
_buckets = new List.filled(_INITIAL_CAPACITY, null);
190190
if (_elementCount > 0) {
191191
_elementCount = 0;
192192
_modificationCount = (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
@@ -503,21 +503,21 @@ abstract class _HashMapIterator<K, V, E> implements Iterator<E> {
503503

504504
class _HashMapKeyIterator<K, V> extends _HashMapIterator<K, V, K> {
505505
_HashMapKeyIterator(_HashMap<K, V> map) : super(map);
506-
K get current => _entry?.key;
506+
K get current => _entry!.key;
507507
}
508508

509509
class _HashMapValueIterator<K, V> extends _HashMapIterator<K, V, V> {
510510
_HashMapValueIterator(_HashMap<K, V> map) : super(map);
511-
V get current => _entry?.value;
511+
V get current => _entry!.value;
512512
}
513513

514514
@patch
515515
class HashSet<E> {
516516
@patch
517517
factory HashSet(
518-
{bool equals(E e1, E e2),
519-
int hashCode(E e),
520-
bool isValidKey(potentialKey)}) {
518+
{bool equals(E e1, E e2)?,
519+
int hashCode(E e)?,
520+
bool isValidKey(potentialKey)?}) {
521521
if (isValidKey == null) {
522522
if (hashCode == null) {
523523
if (equals == null) {
@@ -771,7 +771,7 @@ class _CustomHashSet<E> extends _HashSet<E> {
771771
}
772772

773773
bool containsAll(Iterable<Object?> elements) {
774-
for (Object element in elements) {
774+
for (Object? element in elements) {
775775
if (!_validKey(element) || !this.contains(element)) return false;
776776
}
777777
return true;
@@ -798,7 +798,7 @@ class _HashSetEntry<E> {
798798
_HashSetEntry<E>? next;
799799
_HashSetEntry(this.key, this.hashCode, this.next);
800800

801-
_HashSetEntry<E> remove() {
801+
_HashSetEntry<E>? remove() {
802802
final result = next;
803803
next = null;
804804
return result;

sdk_nnbd/lib/_internal/vm/lib/compact_hash.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class _CompactIterator<E> implements Iterator<E> {
441441
int _offset;
442442
final int _step;
443443
final int _checkSum;
444-
E current;
444+
E? _current;
445445

446446
_CompactIterator(
447447
_HashBase table, this._data, this._len, this._offset, this._step)
@@ -456,13 +456,15 @@ class _CompactIterator<E> implements Iterator<E> {
456456
_offset += _step;
457457
} while (_offset < _len && _HashBase._isDeleted(_data, _data[_offset]));
458458
if (_offset < _len) {
459-
current = internal.unsafeCast<E>(_data[_offset]);
459+
_current = internal.unsafeCast<E>(_data[_offset]);
460460
return true;
461461
} else {
462-
current = null;
462+
_current = null;
463463
return false;
464464
}
465465
}
466+
467+
E get current => _current as E;
466468
}
467469

468470
// Set implementation, analogous to _CompactLinkedHashMap.
@@ -482,7 +484,7 @@ class _CompactLinkedHashSet<E> extends _HashFieldBase
482484
for (int offset = 0; offset < _usedData; offset++) {
483485
Object current = _data[offset];
484486
if (!_HashBase._isDeleted(_data, current)) {
485-
return current;
487+
return current as E;
486488
}
487489
}
488490
throw IterableElementError.noElement();
@@ -492,7 +494,7 @@ class _CompactLinkedHashSet<E> extends _HashFieldBase
492494
for (int offset = _usedData - 1; offset >= 0; offset--) {
493495
Object current = _data[offset];
494496
if (!_HashBase._isDeleted(_data, current)) {
495-
return current;
497+
return current as E;
496498
}
497499
}
498500
throw IterableElementError.noElement();

sdk_nnbd/lib/_internal/vm/lib/date_patch.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class DateTime {
4949
int second, int millisecond, int microsecond, bool isUtc)
5050
: this.isUtc = isUtc,
5151
this._value = _brokenDownDateToValue(year, month, day, hour, minute,
52-
second, millisecond, microsecond, isUtc) {
53-
if (_value == null) throw new ArgumentError();
52+
second, millisecond, microsecond, isUtc) ??
53+
-1 {
54+
if (_value == -1) throw new ArgumentError();
5455
if (isUtc == null) throw new ArgumentError();
5556
}
5657

@@ -347,7 +348,7 @@ class DateTime {
347348
}
348349
if (microsecondsSinceEpoch.abs() >
349350
_maxMillisecondsSinceEpoch * Duration.microsecondsPerMillisecond) {
350-
return null;
351+
throw new ArgumentError();
351352
}
352353
return microsecondsSinceEpoch;
353354
}

sdk_nnbd/lib/_internal/vm/lib/deferred_load_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DeferredLibrary {
1212
Future<Null> load() {
1313
// Dummy implementation that should eventually be replaced by real
1414
// implementation.
15-
Future future = new Future<Null>.value(null);
15+
Future<Null> future = new Future<Null>.value(null);
1616
_loadedLibraries.add(libraryName);
1717
return future;
1818
}

sdk_nnbd/lib/_internal/vm/lib/double_patch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class double {
9191
return sign * (doubleValue * P10[exponent]);
9292
}
9393

94-
static double? _parse(String str) {
94+
static double? _parse(var str) {
9595
int len = str.length;
9696
int start = str._firstNonWhitespace();
9797
if (start == len) return null; // All whitespace.
@@ -104,7 +104,7 @@ class double {
104104

105105
@patch
106106
static double parse(String source,
107-
[@deprecated double onError(String source)]) {
107+
[@deprecated double onError(String source)?]) {
108108
var result = _parse(source);
109109
if (result == null) {
110110
if (onError == null) throw new FormatException("Invalid double", source);

sdk_nnbd/lib/_internal/vm/lib/errors_patch.dart

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Error {
1717
}
1818

1919
@patch
20-
StackTrace get stackTrace => _stackTrace!;
20+
StackTrace? get stackTrace => _stackTrace;
2121

2222
@pragma("vm:entry-point")
2323
StackTrace? _stackTrace;
@@ -32,11 +32,11 @@ class _AssertionError extends Error implements AssertionError {
3232
// out of the script. It expects a Dart stack frame from class
3333
// _AssertionError. Thus we need a Dart stub that calls the native code.
3434
@pragma("vm:entry-point", "call")
35-
static _throwNew(int assertionStart, int assertionEnd, Object message) {
35+
static _throwNew(int assertionStart, int assertionEnd, Object? message) {
3636
_doThrowNew(assertionStart, assertionEnd, message);
3737
}
3838

39-
static _doThrowNew(int assertionStart, int assertionEnd, Object message)
39+
static _doThrowNew(int assertionStart, int assertionEnd, Object? message)
4040
native "AssertionError_throwNew";
4141

4242
@pragma("vm:entry-point", "call")
@@ -54,9 +54,10 @@ class _AssertionError extends Error implements AssertionError {
5454
}
5555

5656
String get _messageString {
57-
if (message == null) return "is not true.";
58-
if (message is String) return message;
59-
return Error.safeToString(message);
57+
final msg = message;
58+
if (msg == null) return "is not true.";
59+
if (msg is String) return msg;
60+
return Error.safeToString(msg);
6061
}
6162

6263
String toString() {
@@ -77,7 +78,7 @@ class _AssertionError extends Error implements AssertionError {
7778
final String _url;
7879
final int _line;
7980
final int _column;
80-
final Object message;
81+
final Object? message;
8182
}
8283

8384
class _TypeError extends _AssertionError implements TypeError {
@@ -88,7 +89,7 @@ class _TypeError extends _AssertionError implements TypeError {
8889
static _throwNew(int location, Object srcValue, _Type dstType, String dstName)
8990
native "TypeError_throwNew";
9091

91-
String toString() => super.message;
92+
String toString() => super.message as String;
9293
}
9394

9495
class _CastError extends Error implements CastError {
@@ -224,7 +225,7 @@ class NoSuchMethodError {
224225
@patch
225226
NoSuchMethodError(Object receiver, Symbol memberName,
226227
List positionalArguments, Map<Symbol, dynamic> namedArguments,
227-
[List existingArgumentNames = null])
228+
[List? existingArgumentNames = null])
228229
: _receiver = receiver,
229230
_invocation = null,
230231
_memberName = memberName,
@@ -277,34 +278,37 @@ class NoSuchMethodError {
277278
@patch
278279
String toString() {
279280
// TODO(regis): Remove this null check once dart2js is updated.
280-
if (_invocation == null) {
281+
final localInvocation = _invocation;
282+
if (localInvocation == null) {
281283
// Use deprecated version of toString.
282284
return _toStringDeprecated();
283285
}
284286
String memberName =
285-
internal.Symbol.computeUnmangledName(_invocation.memberName);
286-
var level = (_invocation._type >> _InvocationMirror._LEVEL_SHIFT) &
287+
internal.Symbol.computeUnmangledName(localInvocation.memberName);
288+
289+
var level = (localInvocation._type >> _InvocationMirror._LEVEL_SHIFT) &
287290
_InvocationMirror._LEVEL_MASK;
288-
var kind = _invocation._type & _InvocationMirror._KIND_MASK;
291+
var kind = localInvocation._type & _InvocationMirror._KIND_MASK;
289292
if (kind == _InvocationMirror._LOCAL_VAR) {
290293
return "NoSuchMethodError: Cannot assign to final variable '$memberName'";
291294
}
292295

293-
StringBuffer typeArgumentsBuf = null;
294-
var typeArguments = _invocation.typeArguments;
296+
StringBuffer? typeArgumentsBuf = null;
297+
final typeArguments = localInvocation.typeArguments;
295298
if ((typeArguments != null) && (typeArguments.length > 0)) {
296-
typeArgumentsBuf = new StringBuffer();
297-
typeArgumentsBuf.write("<");
299+
final argsBuf = new StringBuffer();
300+
argsBuf.write("<");
298301
for (int i = 0; i < typeArguments.length; i++) {
299302
if (i > 0) {
300-
typeArgumentsBuf.write(", ");
303+
argsBuf.write(", ");
301304
}
302-
typeArgumentsBuf.write(Error.safeToString(typeArguments[i]));
305+
argsBuf.write(Error.safeToString(typeArguments[i]));
303306
}
304-
typeArgumentsBuf.write(">");
307+
argsBuf.write(">");
308+
typeArgumentsBuf = argsBuf;
305309
}
306310
StringBuffer argumentsBuf = new StringBuffer();
307-
var positionalArguments = _invocation.positionalArguments;
311+
var positionalArguments = localInvocation.positionalArguments;
308312
int argumentCount = 0;
309313
if (positionalArguments != null) {
310314
for (; argumentCount < positionalArguments.length; argumentCount++) {
@@ -315,7 +319,7 @@ class NoSuchMethodError {
315319
.write(Error.safeToString(positionalArguments[argumentCount]));
316320
}
317321
}
318-
var namedArguments = _invocation.namedArguments;
322+
var namedArguments = localInvocation.namedArguments;
319323
if (namedArguments != null) {
320324
namedArguments.forEach((Symbol key, var value) {
321325
if (argumentCount > 0) {
@@ -328,7 +332,7 @@ class NoSuchMethodError {
328332
});
329333
}
330334
String existingSig =
331-
_existingMethodSignature(_receiver, memberName, _invocation._type);
335+
_existingMethodSignature(_receiver, memberName, localInvocation._type);
332336
String argsMsg = existingSig != null ? " with matching arguments" : "";
333337

334338
assert(kind >= 0 && kind < 5);
@@ -441,25 +445,24 @@ class NoSuchMethodError {
441445

442446
StringBuffer arguments = new StringBuffer();
443447
int argumentCount = 0;
444-
if (_arguments != null) {
445-
for (; argumentCount < _arguments.length; argumentCount++) {
448+
final args = _arguments;
449+
if (args != null) {
450+
for (; argumentCount < args.length; argumentCount++) {
446451
if (argumentCount > 0) {
447452
arguments.write(", ");
448453
}
449-
arguments.write(Error.safeToString(_arguments[argumentCount]));
454+
arguments.write(Error.safeToString(args[argumentCount]));
450455
}
451456
}
452-
if (_namedArguments != null) {
453-
_namedArguments.forEach((Symbol key, var value) {
454-
if (argumentCount > 0) {
455-
arguments.write(", ");
456-
}
457-
arguments.write(internal.Symbol.computeUnmangledName(key));
458-
arguments.write(": ");
459-
arguments.write(Error.safeToString(value));
460-
argumentCount++;
461-
});
462-
}
457+
_namedArguments?.forEach((Symbol key, var value) {
458+
if (argumentCount > 0) {
459+
arguments.write(", ");
460+
}
461+
arguments.write(internal.Symbol.computeUnmangledName(key));
462+
arguments.write(": ");
463+
arguments.write(Error.safeToString(value));
464+
argumentCount++;
465+
});
463466
bool argsMismatch = _existingArgumentNames != null;
464467
String argsMessage = argsMismatch ? " with matching arguments" : "";
465468

@@ -549,11 +552,12 @@ class NoSuchMethodError {
549552

550553
if (argsMismatch) {
551554
StringBuffer formalParameters = new StringBuffer();
552-
for (int i = 0; i < _existingArgumentNames.length; i++) {
555+
final argumentNames = _existingArgumentNames!;
556+
for (int i = 0; i < argumentNames.length; i++) {
553557
if (i > 0) {
554558
formalParameters.write(", ");
555559
}
556-
formalParameters.write(_existingArgumentNames[i]);
560+
formalParameters.write(argumentNames[i]);
557561
}
558562
msgBuf.write("\nFound: $memberName($formalParameters)");
559563
}

0 commit comments

Comments
 (0)