| Index: runtime/vm/parser.cc
|
| ===================================================================
|
| --- runtime/vm/parser.cc (revision 26566)
|
| +++ runtime/vm/parser.cc (working copy)
|
| @@ -2967,6 +2967,7 @@
|
| method->name->ToCString(),
|
| String::Handle(type.UserVisibleName()).ToCString());
|
| } else {
|
| + // TODO(regis): What if the redirection type is malbounded?
|
| redirection_type ^= type.raw();
|
| }
|
| if (CurrentToken() == Token::kPERIOD) {
|
| @@ -5417,6 +5418,7 @@
|
| const Error& error = Error::Handle(signature_type.malformed_error());
|
| function_type.set_malformed_error(error);
|
| }
|
| + // TODO(regis): What if the signature is malbounded?
|
|
|
| // The function type was initially marked as instantiated, but it may
|
| // actually be uninstantiated.
|
| @@ -7091,7 +7093,6 @@
|
|
|
|
|
| AstNode* Parser::ThrowTypeError(intptr_t type_pos, const AbstractType& type) {
|
| - ASSERT(type.IsMalformed());
|
| ArgumentListNode* arguments = new ArgumentListNode(type_pos);
|
| // Location argument.
|
| arguments->Add(new LiteralNode(
|
| @@ -7102,8 +7103,14 @@
|
| arguments->Add(new LiteralNode(type_pos, Symbols::Malformed()));
|
| // Dst name argument.
|
| arguments->Add(new LiteralNode(type_pos, Symbols::Empty()));
|
| - // Malformed type error.
|
| - const Error& error = Error::Handle(type.malformed_error());
|
| + // Malformed type error or malbounded type error.
|
| + Error& error = Error::Handle();
|
| + if (type.IsMalformed()) {
|
| + error = type.malformed_error();
|
| + } else {
|
| + const bool is_malbounded = type.IsMalbounded(&error);
|
| + ASSERT(is_malbounded);
|
| + }
|
| arguments->Add(new LiteralNode(type_pos, String::ZoneHandle(
|
| Symbols::New(error.ToErrorCString()))));
|
| return MakeStaticCall(Symbols::TypeError(),
|
| @@ -7203,10 +7210,11 @@
|
| CaptureInstantiator();
|
| }
|
| right_operand = new TypeNode(type_pos, type);
|
| - // If the type is malformed, it is actually malbounded in checked mode.
|
| - ASSERT(!type.IsMalformed() || FLAG_enable_type_checks);
|
| + // The type is never malformed (mapped to dynamic), but it can be
|
| + // malbounded in checked mode.
|
| + ASSERT(!type.IsMalformed());
|
| if (((op_kind == Token::kIS) || (op_kind == Token::kISNOT)) &&
|
| - type.IsMalformed()) {
|
| + type.IsMalbounded(NULL)) {
|
| // Note that a type error is thrown even if the tested value is null
|
| // in a type test. However, no cast exception is thrown if the value
|
| // is null in a type cast.
|
| @@ -9571,16 +9579,29 @@
|
| ParseType(ClassFinalizer::kCanonicalizeWellFormed));
|
| // In case the type is malformed, throw a dynamic type error after finishing
|
| // parsing the instance creation expression.
|
| - if (!type.IsMalformed() && (type.IsTypeParameter() || type.IsDynamicType())) {
|
| - // Replace the type with a malformed type.
|
| - type = ClassFinalizer::NewFinalizedMalformedType(
|
| - Error::Handle(), // No previous error.
|
| - current_class(),
|
| - type_pos,
|
| - "%s'%s' cannot be instantiated",
|
| - type.IsTypeParameter() ? "type parameter " : "",
|
| - type.IsTypeParameter() ?
|
| - String::Handle(type.UserVisibleName()).ToCString() : "dynamic");
|
| + if (!type.IsMalformed()) {
|
| + if (type.IsTypeParameter() || type.IsDynamicType()) {
|
| + // Replace the type with a malformed type.
|
| + type = ClassFinalizer::NewFinalizedMalformedType(
|
| + Error::Handle(), // No previous error.
|
| + current_class(),
|
| + type_pos,
|
| + "%s'%s' cannot be instantiated",
|
| + type.IsTypeParameter() ? "type parameter " : "",
|
| + type.IsTypeParameter() ?
|
| + String::Handle(type.UserVisibleName()).ToCString() : "dynamic");
|
| + } else if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) {
|
| + Error& bound_error = Error::Handle();
|
| + if (type.IsMalbounded(&bound_error)) {
|
| + // Replace the type with a malformed type.
|
| + type = ClassFinalizer::NewFinalizedMalformedType(
|
| + bound_error,
|
| + current_class(),
|
| + type_pos,
|
| + "malbounded type '%s' cannot be instantiated",
|
| + String::Handle(type.UserVisibleName()).ToCString());
|
| + }
|
| + }
|
| }
|
|
|
| // The grammar allows for an optional ('.' identifier)? after the type, which
|
|
|