@@ -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
8384class _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
9495class _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 ("\n Found: $memberName ($formalParameters )" );
559563 }
0 commit comments