| Index: runtime/vm/object.cc
|
| ===================================================================
|
| --- runtime/vm/object.cc (revision 9601)
|
| +++ runtime/vm/object.cc (working copy)
|
| @@ -3690,26 +3690,71 @@
|
| }
|
|
|
|
|
| +intptr_t Function::NumberOfImplicitParameters() const {
|
| + if (kind() == RawFunction::kConstructor) {
|
| + if (is_static()) {
|
| + ASSERT(IsFactory());
|
| + return 1; // Type arguments.
|
| + } else {
|
| + ASSERT(IsConstructor());
|
| + return 2; // Instance, phase.
|
| + }
|
| + }
|
| + if (!is_static()) {
|
| + return 1; // Receiver.
|
| + }
|
| + return 0; // No implicit parameters.
|
| +}
|
| +
|
| +
|
| bool Function::AreValidArgumentCounts(int num_arguments,
|
| - int num_named_arguments) const {
|
| + int num_named_arguments,
|
| + String* error_message) const {
|
| if (num_arguments > NumberOfParameters()) {
|
| + if (error_message != NULL) {
|
| + const intptr_t kMessageBufferSize = 64;
|
| + char message_buffer[kMessageBufferSize];
|
| + // Hide implicit parameters to the user.
|
| + const intptr_t num_hidden_params = NumberOfImplicitParameters();
|
| + OS::SNPrint(message_buffer,
|
| + kMessageBufferSize,
|
| + "%d passed, %s%d expected",
|
| + num_arguments - num_hidden_params,
|
| + num_optional_parameters() > 0 ? "at most " : "",
|
| + NumberOfParameters() - num_hidden_params);
|
| + *error_message = String::New(message_buffer);
|
| + }
|
| return false; // Too many arguments.
|
| }
|
| const int num_positional_args = num_arguments - num_named_arguments;
|
| if (num_positional_args < num_fixed_parameters()) {
|
| + if (error_message != NULL) {
|
| + const intptr_t kMessageBufferSize = 64;
|
| + char message_buffer[kMessageBufferSize];
|
| + // Hide implicit parameters to the user.
|
| + const intptr_t num_hidden_params = NumberOfImplicitParameters();
|
| + OS::SNPrint(message_buffer,
|
| + kMessageBufferSize,
|
| + "%d %spassed, %d expected",
|
| + num_positional_args - num_hidden_params,
|
| + num_optional_parameters() > 0 ? "positional " : "",
|
| + num_fixed_parameters() - num_hidden_params);
|
| + *error_message = String::New(message_buffer);
|
| + }
|
| return false; // Too few arguments.
|
| }
|
| return true;
|
| }
|
|
|
|
|
| -// TODO(regis): Return some sort of diagnosis information so that we
|
| -// can improve the error messages generated by the parser.
|
| bool Function::AreValidArguments(int num_arguments,
|
| - const Array& argument_names) const {
|
| + const Array& argument_names,
|
| + String* error_message) const {
|
| const int num_named_arguments =
|
| argument_names.IsNull() ? 0 : argument_names.Length();
|
| - if (!AreValidArgumentCounts(num_arguments, num_named_arguments)) {
|
| + if (!AreValidArgumentCounts(num_arguments,
|
| + num_named_arguments,
|
| + error_message)) {
|
| return false;
|
| }
|
| // Verify that all argument names are valid parameter names.
|
| @@ -3729,6 +3774,15 @@
|
| }
|
| }
|
| if (!found) {
|
| + if (error_message != NULL) {
|
| + const intptr_t kMessageBufferSize = 64;
|
| + char message_buffer[kMessageBufferSize];
|
| + OS::SNPrint(message_buffer,
|
| + kMessageBufferSize,
|
| + "no optional formal parameter named '%s'",
|
| + argument_name.ToCString());
|
| + *error_message = String::New(message_buffer);
|
| + }
|
| return false;
|
| }
|
| }
|
|
|