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

Side by Side Diff: runtime/lib/errors_patch.dart

Issue 14652008: Fix error reporting when calling static methods and closures withh mismatched arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
11 patch class NoSuchMethodError { 11 patch class NoSuchMethodError {
12 // The compiler emits a call to _throwNew when it cannot resolve a static 12 // The compiler emits a call to _throwNew when it cannot resolve a static
13 // method at compile time. The receiver is actually the literal class of the 13 // method at compile time. The receiver is actually the literal class of the
14 // unresolved method. 14 // unresolved method.
15 static void _throwNew(Object receiver, 15 static void _throwNew(Object receiver,
16 String memberName, 16 String memberName,
17 int invocation_type, 17 int invocation_type,
18 List arguments, 18 List arguments,
19 List argumentNames, 19 List argumentNames,
20 List existingArgumentNames) { 20 List existingArgumentNames) {
21 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length; 21 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length;
22 int numPositionalArguments = arguments == null ? 0 : arguments.length; 22 int numPositionalArguments = arguments == null ? 0 : arguments.length;
23 numPositionalArguments -= numNamedArguments; 23 numPositionalArguments -= numNamedArguments;
24 List positionalArguments; 24 List positionalArguments;
25 if (numPositionalArguments == 0) { 25 if (numPositionalArguments == 0) {
26 positionalArguments = []; 26 // Differ between no arguments specified and 0 arguments.
27 // TODO(srdjan): This can currently occur for unresolvable static methods.
28 // In that case, the arguments are evaluated but not passed to the
29 // throwing stub (see EffectGraphVisitor::BuildThrowNoSuchMethodError and
30 // Parser::ThrowNoSuchMethodError)).
31 positionalArguments = argumentNames == null ? null : [];
27 } else { 32 } else {
28 positionalArguments = arguments.sublist(0, numPositionalArguments); 33 positionalArguments = arguments.sublist(0, numPositionalArguments);
29 } 34 }
30 Map<String, dynamic> namedArguments = new Map<String, dynamic>(); 35 Map<String, dynamic> namedArguments = new Map<String, dynamic>();
31 for (int i = 0; i < numNamedArguments; i++) { 36 for (int i = 0; i < numNamedArguments; i++) {
32 var arg_value = arguments[numPositionalArguments + i]; 37 var arg_value = arguments[numPositionalArguments + i];
33 namedArguments[argumentNames[i]] = arg_value; 38 namedArguments[argumentNames[i]] = arg_value;
34 } 39 }
35 throw new NoSuchMethodError._withType(receiver, 40 throw new NoSuchMethodError._withType(receiver,
36 memberName, 41 memberName,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 var type_str = 77 var type_str =
73 (const ["method", "getter", "setter", "getter or setter"])[type]; 78 (const ["method", "getter", "setter", "getter or setter"])[type];
74 var args_message = args_mismatch ? " with matching arguments" : ""; 79 var args_message = args_mismatch ? " with matching arguments" : "";
75 var msg; 80 var msg;
76 switch (level) { 81 switch (level) {
77 case _InvocationMirror._DYNAMIC: { 82 case _InvocationMirror._DYNAMIC: {
78 if (_receiver == null) { 83 if (_receiver == null) {
79 msg = "The null object does not have a $type_str '$_memberName'" 84 msg = "The null object does not have a $type_str '$_memberName'"
80 "$args_message."; 85 "$args_message.";
81 } else { 86 } else {
82 msg = "Class '${_receiver.runtimeType}' has no instance $type_str " 87 if (_receiver is Function) {
83 "'$_memberName'$args_message."; 88 msg = "Closure call with mismatched arguments: "
89 "function '$_memberName'";
90 } else {
91 msg = "Class '${_receiver.runtimeType}' has no instance $type_str "
92 "'$_memberName'$args_message.";
93 }
84 } 94 }
85 break; 95 break;
86 } 96 }
87 case _InvocationMirror._STATIC: { 97 case _InvocationMirror._STATIC: {
88 msg = "No static $type_str '$_memberName' declared in class " 98 msg = "No static $type_str '$_memberName' declared in class "
89 "'$_receiver'."; 99 "'$_receiver'.";
90 break; 100 break;
91 } 101 }
92 case _InvocationMirror._CONSTRUCTOR: { 102 case _InvocationMirror._CONSTRUCTOR: {
93 msg = "No constructor '$_memberName' declared in class '$_receiver'."; 103 msg = "No constructor '$_memberName' declared in class '$_receiver'.";
94 break; 104 break;
95 } 105 }
96 case _InvocationMirror._TOP_LEVEL: { 106 case _InvocationMirror._TOP_LEVEL: {
97 msg = "No top-level $type_str '$_memberName' declared."; 107 msg = "No top-level $type_str '$_memberName'$args_message declared.";
98 break; 108 break;
99 } 109 }
100 } 110 }
101 return "$msg\n\n"; 111 return "$msg\n\n";
102 } 112 }
103 113
104 /* patch */ String toString() { 114 /* patch */ String toString() {
105 StringBuffer actual_buf = new StringBuffer(); 115 StringBuffer actual_buf = new StringBuffer();
106 int i = 0; 116 int i = 0;
107 if (_arguments != null) { 117 if (_arguments == null) {
118 // Actual arguments unknown.
119 // TODO(srdjan): Remove once arguments are passed for unresolvable
120 // static methods.
121 actual_buf.write("...");
122 } else {
108 for (; i < _arguments.length; i++) { 123 for (; i < _arguments.length; i++) {
109 if (i > 0) { 124 if (i > 0) {
110 actual_buf.write(", "); 125 actual_buf.write(", ");
111 } 126 }
112 actual_buf.write(Error.safeToString(_arguments[i])); 127 actual_buf.write(Error.safeToString(_arguments[i]));
113 } 128 }
114 } 129 }
115 if (_namedArguments != null) { 130 if (_namedArguments != null) {
116 _namedArguments.forEach((String key, var value) { 131 _namedArguments.forEach((String key, var value) {
117 if (i > 0) { 132 if (i > 0) {
(...skipping 29 matching lines...) Expand all
147 msg_buf.write( 162 msg_buf.write(
148 "NoSuchMethodError: incorrect number of arguments passed to " 163 "NoSuchMethodError: incorrect number of arguments passed to "
149 "method named '$_memberName'\n" 164 "method named '$_memberName'\n"
150 "Receiver: $receiver_str\n" 165 "Receiver: $receiver_str\n"
151 "Tried calling: $_memberName($actualParameters)\n" 166 "Tried calling: $_memberName($actualParameters)\n"
152 "Found: $_memberName($formalParameters)"); 167 "Found: $_memberName($formalParameters)");
153 } 168 }
154 return msg_buf.toString(); 169 return msg_buf.toString();
155 } 170 }
156 } 171 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698