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

Unified Diff: runtime/lib/errors_patch.dart

Issue 2507493003: Improve noSuchMethod error message for type objects. (Closed)
Patch Set: improve message Created 4 years, 1 month 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/errors_patch.dart
diff --git a/runtime/lib/errors_patch.dart b/runtime/lib/errors_patch.dart
index bf0405922f5d7bcce314b3ff7c117fcf186fe3e5..989eb57424f9a6ecece0f7ac88165f0368ae33f6 100644
--- a/runtime/lib/errors_patch.dart
+++ b/runtime/lib/errors_patch.dart
@@ -273,6 +273,7 @@ class _InternalError {
}
StringBuffer msg_buf = new StringBuffer("NoSuchMethodError: ");
+ bool is_type_call = false;
switch (level) {
case _InvocationMirror._DYNAMIC: {
if (_receiver == null) {
@@ -286,6 +287,13 @@ class _InternalError {
if (_receiver is Function) {
msg_buf.writeln("Closure call with mismatched arguments: "
"function '$memberName'");
+ } else if (_receiver is _Type && memberName == "call") {
+ is_type_call = true;
+ String name = _receiver.toString();
+ msg_buf.writeln("Attempted to use type '$name' as a function. "
+ "Since types do not define a method 'call', this is not "
+ "possible. Did you intend to call the $name constructor and "
+ "forget the 'new' operator?");
} else {
msg_buf.writeln("Class '${_receiver.runtimeType}' has no instance "
"$type_str '$memberName'$args_message.");
@@ -324,7 +332,8 @@ class _InternalError {
}
if (type == _InvocationMirror._METHOD) {
- msg_buf.write("Tried calling: $memberName($arguments)");
+ String m = is_type_call ? "$_receiver" : "$memberName";
+ msg_buf.write("Tried calling: $m($arguments)");
} else if (argumentCount == 0) {
msg_buf.write("Tried calling: $memberName");
} else if (type == _InvocationMirror._SETTER) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698