OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 @patch class Error { | 5 @patch class Error { |
6 @patch static String _objectToString(Object object) { | 6 @patch static String _objectToString(Object object) { |
7 return Object._toString(object); | 7 return Object._toString(object); |
8 } | 8 } |
9 | 9 |
10 @patch static String _stringToSafeString(String string) { | 10 @patch static String _stringToSafeString(String string) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 bool args_mismatch = _existingArgumentNames != null; | 266 bool args_mismatch = _existingArgumentNames != null; |
267 String args_message = args_mismatch ? " with matching arguments" : ""; | 267 String args_message = args_mismatch ? " with matching arguments" : ""; |
268 | 268 |
269 String type_str; | 269 String type_str; |
270 if (type >= 0 && type < 5) { | 270 if (type >= 0 && type < 5) { |
271 type_str = (const ["method", "getter", "setter", "getter or setter", | 271 type_str = (const ["method", "getter", "setter", "getter or setter", |
272 "variable"])[type]; | 272 "variable"])[type]; |
273 } | 273 } |
274 | 274 |
275 StringBuffer msg_buf = new StringBuffer("NoSuchMethodError: "); | 275 StringBuffer msg_buf = new StringBuffer("NoSuchMethodError: "); |
| 276 bool is_type_call = false; |
276 switch (level) { | 277 switch (level) { |
277 case _InvocationMirror._DYNAMIC: { | 278 case _InvocationMirror._DYNAMIC: { |
278 if (_receiver == null) { | 279 if (_receiver == null) { |
279 if (args_mismatch) { | 280 if (args_mismatch) { |
280 msg_buf.writeln("The null object does not have a $type_str " | 281 msg_buf.writeln("The null object does not have a $type_str " |
281 "'$memberName'$args_message."); | 282 "'$memberName'$args_message."); |
282 } else { | 283 } else { |
283 msg_buf.writeln("The $type_str '$memberName' was called on null."); | 284 msg_buf.writeln("The $type_str '$memberName' was called on null."); |
284 } | 285 } |
285 } else { | 286 } else { |
286 if (_receiver is Function) { | 287 if (_receiver is Function) { |
287 msg_buf.writeln("Closure call with mismatched arguments: " | 288 msg_buf.writeln("Closure call with mismatched arguments: " |
288 "function '$memberName'"); | 289 "function '$memberName'"); |
| 290 } else if (_receiver is _Type && memberName == "call") { |
| 291 is_type_call = true; |
| 292 String name = _receiver.toString(); |
| 293 msg_buf.writeln("Attempted to use type '$name' as a function. " |
| 294 "Since types do not define a method 'call', this is not " |
| 295 "possible. Did you intend to call the $name constructor and " |
| 296 "forget the 'new' operator?"); |
289 } else { | 297 } else { |
290 msg_buf.writeln("Class '${_receiver.runtimeType}' has no instance " | 298 msg_buf.writeln("Class '${_receiver.runtimeType}' has no instance " |
291 "$type_str '$memberName'$args_message."); | 299 "$type_str '$memberName'$args_message."); |
292 } | 300 } |
293 } | 301 } |
294 break; | 302 break; |
295 } | 303 } |
296 case _InvocationMirror._SUPER: { | 304 case _InvocationMirror._SUPER: { |
297 msg_buf.writeln("Super class of class '${_receiver.runtimeType}' has " | 305 msg_buf.writeln("Super class of class '${_receiver.runtimeType}' has " |
298 "no instance $type_str '$memberName'$args_message."); | 306 "no instance $type_str '$memberName'$args_message."); |
(...skipping 18 matching lines...) Expand all Loading... |
317 } | 325 } |
318 } | 326 } |
319 | 327 |
320 if (level == _InvocationMirror._TOP_LEVEL) { | 328 if (level == _InvocationMirror._TOP_LEVEL) { |
321 msg_buf.writeln("Receiver: top-level"); | 329 msg_buf.writeln("Receiver: top-level"); |
322 } else { | 330 } else { |
323 msg_buf.writeln("Receiver: ${Error.safeToString(_receiver)}"); | 331 msg_buf.writeln("Receiver: ${Error.safeToString(_receiver)}"); |
324 } | 332 } |
325 | 333 |
326 if (type == _InvocationMirror._METHOD) { | 334 if (type == _InvocationMirror._METHOD) { |
327 msg_buf.write("Tried calling: $memberName($arguments)"); | 335 String m = is_type_call ? "$_receiver" : "$memberName"; |
| 336 msg_buf.write("Tried calling: $m($arguments)"); |
328 } else if (argumentCount == 0) { | 337 } else if (argumentCount == 0) { |
329 msg_buf.write("Tried calling: $memberName"); | 338 msg_buf.write("Tried calling: $memberName"); |
330 } else if (type == _InvocationMirror._SETTER) { | 339 } else if (type == _InvocationMirror._SETTER) { |
331 msg_buf.write("Tried calling: $memberName$arguments"); | 340 msg_buf.write("Tried calling: $memberName$arguments"); |
332 } else { | 341 } else { |
333 msg_buf.write("Tried calling: $memberName = $arguments"); | 342 msg_buf.write("Tried calling: $memberName = $arguments"); |
334 } | 343 } |
335 | 344 |
336 if (args_mismatch) { | 345 if (args_mismatch) { |
337 StringBuffer formalParameters = new StringBuffer(); | 346 StringBuffer formalParameters = new StringBuffer(); |
338 for (int i = 0; i < _existingArgumentNames.length; i++) { | 347 for (int i = 0; i < _existingArgumentNames.length; i++) { |
339 if (i > 0) { | 348 if (i > 0) { |
340 formalParameters.write(", "); | 349 formalParameters.write(", "); |
341 } | 350 } |
342 formalParameters.write(_existingArgumentNames[i]); | 351 formalParameters.write(_existingArgumentNames[i]); |
343 } | 352 } |
344 msg_buf.write("\nFound: $memberName($formalParameters)"); | 353 msg_buf.write("\nFound: $memberName($formalParameters)"); |
345 } | 354 } |
346 | 355 |
347 return msg_buf.toString(); | 356 return msg_buf.toString(); |
348 } | 357 } |
349 } | 358 } |
350 | 359 |
351 | 360 |
352 class _CompileTimeError extends Error { | 361 class _CompileTimeError extends Error { |
353 final String _errorMsg; | 362 final String _errorMsg; |
354 _CompileTimeError(this._errorMsg); | 363 _CompileTimeError(this._errorMsg); |
355 String toString() => _errorMsg; | 364 String toString() => _errorMsg; |
356 } | 365 } |
OLD | NEW |