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

Unified Diff: runtime/lib/object.cc

Issue 9307074: If programmer mistakes the number of arguments, VM throws noSuchMethod. Extend reporting to repor... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/object.cc
===================================================================
--- runtime/lib/object.cc (revision 3908)
+++ runtime/lib/object.cc (working copy)
@@ -29,6 +29,38 @@
dart_arguments.Add(&instance);
dart_arguments.Add(&function_name);
dart_arguments.Add(&func_args);
+ // Report if a function with same name (but different arguments) has been
+ // found.
+ Class& instance_class = Class::Handle(instance.clazz());
+ Function& function =
+ Function::Handle(instance_class.LookupDynamicFunction(function_name));
+ while (function.IsNull()) {
+ instance_class = instance_class.SuperClass();
+ if (instance_class.IsNull()) break;
+ function = instance_class.LookupDynamicFunction(function_name);
+ }
+ if (!function.IsNull()) {
+ String& tmp = String::Handle();
+ String& extra_message = String::Handle();
+ tmp = String::NewSymbol("\nFound '");
+ extra_message = String::Concat(tmp, function_name);
+ tmp = String::NewSymbol("(");
+ extra_message = String::Concat(extra_message, tmp);
+ const int total_num_paramaters =
+ function.num_fixed_parameters() + function.num_optional_parameters();
+ // 0 is the receiver ('this'), skip it.
+ for (int i = 1; i < total_num_paramaters; i++) {
+ if (i > 1) {
+ tmp = String::NewSymbol(", ");
+ extra_message = String::Concat(extra_message, tmp);
+ }
+ tmp = function.ParameterNameAt(i);
+ extra_message = String::Concat(extra_message, tmp);
+ }
+ tmp = String::NewSymbol(")'");
+ extra_message = String::Concat(extra_message, tmp);
+ dart_arguments.Add(&extra_message);
+ }
Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments);
}
« no previous file with comments | « corelib/src/exceptions.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698