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

Unified Diff: runtime/vm/code_generator.cc

Issue 9705041: Fix 2172: report 'int' instead of Smi, Mint and Bigint when throwing TypeError. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_generator.cc
===================================================================
--- runtime/vm/code_generator.cc (revision 5522)
+++ runtime/vm/code_generator.cc (working copy)
@@ -413,6 +413,17 @@
}
+// For error reporting simplify type name, e.g, all integer types (Smi, Mint,
+// Bigint) a re reported as 'int'.
+static RawString* GetSimpleTypeName(const Instance& value) {
+ if (value.IsInteger()) {
+ return String::NewSymbol("int");
+ } else {
+ return Type::Handle(value.GetType()).Name();
+ }
+}
+
+
// Check that the type of the given instance is a subtype of the given type and
// can therefore be assigned.
// Arg0: index of the token of the assignment (source location).
@@ -466,8 +477,7 @@
OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString());
}
if (!is_instance_of) {
- const Type& src_type = Type::Handle(src_instance.GetType());
- const String& src_type_name = String::Handle(src_type.Name());
+ String& src_type_name = String::Handle(GetSimpleTypeName(src_instance));
String& dst_type_name = String::Handle();
if (!dst_type.IsInstantiated()) {
// Instantiate dst_type before reporting the error.
@@ -502,8 +512,7 @@
const Instance& src_instance = Instance::CheckedHandle(arguments.At(1));
ASSERT(src_instance.IsNull() || !src_instance.IsBool());
const Type& bool_interface = Type::Handle(Type::BoolInterface());
- const Type& src_type = Type::Handle(src_instance.GetType());
- const String& src_type_name = String::Handle(src_type.Name());
+ const String& src_type_name = String::Handle(GetSimpleTypeName(src_instance));
const String& bool_type_name = String::Handle(bool_interface.Name());
const String& expr = String::Handle(String::NewSymbol("boolean expression"));
const String& no_malformed_type_error = String::Handle();
@@ -528,8 +537,7 @@
const String& dst_name = String::CheckedHandle(arguments.At(2));
const String& malformed_error = String::CheckedHandle(arguments.At(3));
const String& dst_type_name = String::Handle(String::NewSymbol("malformed"));
- const String& src_type_name =
- String::Handle(Type::Handle(src_value.GetType()).Name());
+ const String& src_type_name = String::Handle(GetSimpleTypeName(src_value));
Exceptions::CreateAndThrowTypeError(location, src_type_name,
dst_type_name, dst_name, malformed_error);
UNREACHABLE();
@@ -575,8 +583,7 @@
char buf[256];
OS::SNPrint(buf, sizeof(buf), "%s[%d]",
rest_name.ToCString(), static_cast<int>(i));
- const String& src_type_name =
- String::Handle(Type::Handle(elem.GetType()).Name());
+ const String& src_type_name = String::Handle(GetSimpleTypeName(elem));
String& dst_type_name = String::Handle();
if (!element_type.IsInstantiated()) {
// Instantiate element_type before reporting the error.
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698