Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Unified Diff: runtime/lib/errors_patch.dart

Issue 12328019: - Improve the message for NoSuchMethodErrors that are (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/invocation_mirror.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/errors_patch.dart
===================================================================
--- runtime/lib/errors_patch.dart (revision 18846)
+++ runtime/lib/errors_patch.dart (working copy)
@@ -14,6 +14,7 @@
// unresolved method.
static void _throwNew(Object receiver,
String memberName,
+ int invocation_type,
List arguments,
List argumentNames,
List existingArgumentNames) {
@@ -31,20 +32,75 @@
var arg_value = arguments[numPositionalArguments + i];
namedArguments[argumentNames[i]] = arg_value;
}
- throw new NoSuchMethodError(receiver,
+ throw new NoSuchMethodError._withType(receiver,
memberName,
+ invocation_type,
positionalArguments,
namedArguments,
existingArgumentNames);
}
+ // Remember the type from the invocation mirror or static compilation
+ // analysis when thrown directly with _throwNew. A negative value means
+ // that no information is available.
+ final int _invocation_type;
+
const NoSuchMethodError(Object this._receiver,
String this._memberName,
List this._arguments,
Map<String,dynamic> this._namedArguments,
[List existingArgumentNames = null])
+ : this._existingArgumentNames = existingArgumentNames,
+ this._invocation_type = -1;
+
+ const NoSuchMethodError._withType(Object this._receiver,
+ String this._memberName,
+ this._invocation_type,
+ List this._arguments,
+ Map<String,dynamic> this._namedArguments,
+ [List existingArgumentNames = null])
: this._existingArgumentNames = existingArgumentNames;
+
+ String _developerMessage(args_mismatch) {
+ if (_invocation_type < 0) {
+ return "";
+ }
+ var type = _invocation_type & _InvocationMirror._TYPE_MASK;
+ var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) &
+ _InvocationMirror._CALL_MASK;
+ var type_str =
+ (const ["method", "getter", "setter", "getter or setter"])[type];
+ var args_message = args_mismatch ? " with matching arguments" : "";
+ var msg;
+ switch (level) {
+ case _InvocationMirror._DYNAMIC: {
+ if (_receiver == null) {
+ msg = "The null object does not have a $type_str '$_memberName'"
+ "$args_message.";
+ } else {
+ msg = "Class '${_receiver.runtimeType}' has no instance $type_str "
+ "'$_memberName'$args_message.";
+ }
+ break;
+ }
+ case _InvocationMirror._STATIC: {
+ msg = "No static $type_str '$_memberName' declared in class "
+ "'$_receiver'.";
+ break;
+ }
+ case _InvocationMirror._CONSTRUCTOR: {
+ msg = "No constructor '$_memberName' declared in class '$_receiver'.";
+ break;
+ }
+ case _InvocationMirror._TOP_LEVEL: {
+ msg = "No top-level $type_str '$_memberName' declared.";
+ break;
+ }
+ }
+ return "$msg\n\n";
+ }
+
/* patch */ String toString() {
StringBuffer actual_buf = new StringBuffer();
int i = 0;
@@ -67,8 +123,9 @@
i++;
});
}
- StringBuffer msg_buf = new StringBuffer();
- if (_existingArgumentNames == null) {
+ var args_mismatch = _existingArgumentNames != null;
+ StringBuffer msg_buf = new StringBuffer(_developerMessage(args_mismatch));
+ if (!args_mismatch) {
msg_buf.add(
"NoSuchMethodError : method not found: '$_memberName'\n"
"Receiver: ${Error.safeToString(_receiver)}\n"
« no previous file with comments | « no previous file | runtime/lib/invocation_mirror.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698