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

Unified Diff: runtime/vm/flow_graph_builder.cc

Issue 27420002: Throw a dynamic type error instead of a CastError in a type cast with a (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_builder.cc
===================================================================
--- runtime/vm/flow_graph_builder.cc (revision 28684)
+++ runtime/vm/flow_graph_builder.cc (working copy)
@@ -1298,7 +1298,7 @@
void EffectGraphVisitor::BuildTypeCast(ComparisonNode* node) {
ASSERT(Token::IsTypeCastOperator(node->kind()));
const AbstractType& type = node->right()->AsTypeNode()->type();
- ASSERT(type.IsFinalized()); // The type in a type cast may be malformed.
+ ASSERT(type.IsFinalized() && !type.IsMalformed() && !type.IsMalbounded());
ValueGraphVisitor for_value(owner(), temp_index());
node->left()->Visit(&for_value);
const String& dst_name = String::ZoneHandle(
@@ -1315,54 +1315,47 @@
ASSERT(Token::IsTypeCastOperator(node->kind()));
ASSERT(!node->right()->AsTypeNode()->type().IsNull());
const AbstractType& type = node->right()->AsTypeNode()->type();
- ASSERT(type.IsFinalized()); // The type in a type cast may be malformed.
+ ASSERT(type.IsFinalized() && !type.IsMalformed() && !type.IsMalbounded());
ValueGraphVisitor for_value(owner(), temp_index());
node->left()->Visit(&for_value);
Append(for_value);
const String& dst_name = String::ZoneHandle(
Symbols::New(Exceptions::kCastErrorDstName));
- if (type.IsMalformed() || type.IsMalbounded()) {
- ReturnValue(BuildAssignableValue(node->token_pos(),
- for_value.value(),
- type,
- dst_name));
+ if (CanSkipTypeCheck(node->token_pos(),
+ for_value.value(),
+ type,
+ dst_name)) {
+ ReturnValue(for_value.value());
+ return;
+ }
+ PushArgumentInstr* push_left = PushArgument(for_value.value());
+ PushArgumentInstr* push_instantiator = NULL;
+ PushArgumentInstr* push_type_args = NULL;
+ if (type.IsInstantiated()) {
+ push_instantiator = PushArgument(BuildNullValue());
+ push_type_args = PushArgument(BuildNullValue());
} else {
- if (CanSkipTypeCheck(node->token_pos(),
- for_value.value(),
- type,
- dst_name)) {
- ReturnValue(for_value.value());
- return;
- }
- PushArgumentInstr* push_left = PushArgument(for_value.value());
- PushArgumentInstr* push_instantiator = NULL;
- PushArgumentInstr* push_type_args = NULL;
- if (type.IsInstantiated()) {
- push_instantiator = PushArgument(BuildNullValue());
- push_type_args = PushArgument(BuildNullValue());
- } else {
- BuildTypecheckPushArguments(node->token_pos(),
- &push_instantiator,
- &push_type_args);
- }
- ZoneGrowableArray<PushArgumentInstr*>* arguments =
- new ZoneGrowableArray<PushArgumentInstr*>(4);
- arguments->Add(push_left);
- arguments->Add(push_instantiator);
- arguments->Add(push_type_args);
- Value* type_arg = Bind(new ConstantInstr(type));
- arguments->Add(PushArgument(type_arg));
- const intptr_t kNumArgsChecked = 1;
- InstanceCallInstr* call = new InstanceCallInstr(
- node->token_pos(),
- Library::PrivateCoreLibName(Symbols::_as()),
- node->kind(),
- arguments,
- Object::null_array(), // No argument names.
- kNumArgsChecked,
- owner()->ic_data_array());
- ReturnDefinition(call);
+ BuildTypecheckPushArguments(node->token_pos(),
+ &push_instantiator,
+ &push_type_args);
}
+ ZoneGrowableArray<PushArgumentInstr*>* arguments =
+ new ZoneGrowableArray<PushArgumentInstr*>(4);
+ arguments->Add(push_left);
+ arguments->Add(push_instantiator);
+ arguments->Add(push_type_args);
+ Value* type_arg = Bind(new ConstantInstr(type));
+ arguments->Add(PushArgument(type_arg));
+ const intptr_t kNumArgsChecked = 1;
+ InstanceCallInstr* call = new InstanceCallInstr(
+ node->token_pos(),
+ Library::PrivateCoreLibName(Symbols::_as()),
+ node->kind(),
+ arguments,
+ Object::null_array(), // No argument names.
+ kNumArgsChecked,
+ owner()->ic_data_array());
+ ReturnDefinition(call);
}
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698