Fix VM implementation of CastError not to extend TypeError (issue 5280).

Remove non-compliant fields in various Error classes (issue 10144).
Remove implicit constructor when patching in a constructor (issue 12217).
Patch corelib Error classes instead of declaring subclasses.
Update tests and status files.

R=asiva@google.com, srdjan@google.com

Review URL: https://codereview.chromium.org//21832003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25782 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
regis@google.com 2013-08-05 18:35:04 +00:00
parent 541ef31a2b
commit 09bcdc6d6d
29 changed files with 404 additions and 575 deletions

View file

@ -17,10 +17,8 @@
'double.cc',
'double.dart',
'double_patch.dart',
'error.cc',
'error.dart',
'errors.cc',
'errors_patch.dart',
'error.h',
'expando_patch.dart',
'function.cc',
'function_patch.dart',

View file

@ -1,119 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Errors are created and thrown by DartVM only.
// Changes here should also be reflected in corelib/error.dart as well
class _AssertionErrorImplementation extends AssertionError {
_AssertionErrorImplementation(
this.failedAssertion, this.url, this.line, this.column);
static _throwNew(int assertionStart, int assertionEnd)
native "AssertionError_throwNew";
String toString() {
return "'$url': Failed assertion: line $line pos $column: "
"'$failedAssertion' is not true.";
}
final String failedAssertion;
final String url;
final int line;
final int column;
}
class _TypeErrorImplementation
extends _AssertionErrorImplementation
implements TypeError {
_TypeErrorImplementation(
String failedAssertion, String url, int line, int column,
this.srcType, this.dstType, this.dstName, this._malformedError)
: super(failedAssertion, url, line, column);
static _throwNew(int location,
Object src_value,
String dst_type_name,
String dst_name,
String malformed_error)
native "TypeError_throwNew";
String toString() {
String str = (_malformedError != null) ? _malformedError : "";
if ((dstName != null) && (dstName.length > 0)) {
str = "${str}type '$srcType' is not a subtype of "
"type '$dstType' of '$dstName'.";
} else {
str = "${str}malformed type used.";
}
return str;
}
final String srcType;
final String dstType;
final String dstName;
final String _malformedError;
}
class _CastErrorImplementation
extends _TypeErrorImplementation
implements CastError {
_CastErrorImplementation(
String failedAssertion, String url, int line, int column,
String srcType, String dstType, String dstName, String malformedError)
: super(failedAssertion, url, line, column,
srcType, dstType, dstName, malformedError);
// A CastError is allocated by TypeError._throwNew() when dst_name equals
// Exceptions::kCastErrorDstName.
String toString() {
String str = (_malformedError != null) ? _malformedError : "";
if ((dstName != null) && (dstName.length > 0)) {
str = "${str}type '$srcType' is not a subtype of "
"type '$dstType' in type cast.";
} else {
str = "${str}malformed type used in type cast.";
}
return str;
}
}
class _FallThroughErrorImplementation extends FallThroughError {
_FallThroughErrorImplementation(this._url, this._line);
static _throwNew(int case_clause_pos) native "FallThroughError_throwNew";
String toString() {
return "'$_url': Switch case fall-through at line $_line.";
}
final String _url;
final int _line;
}
class _InternalError {
const _InternalError(this._msg);
String toString() => "InternalError: '${_msg}'";
final String _msg;
}
class _AbstractClassInstantiationErrorImplementation
extends AbstractClassInstantiationError {
_AbstractClassInstantiationErrorImplementation(
String className, this._url, this._line)
: super(className);
static _throwNew(int case_clause_pos, String className)
native "AbstractClassInstantiationError_throwNew";
String toString() {
return "Cannot instantiate abstract class $_className: "
"_url '$_url' line $_line";
}
final String _url;
final int _line;
}

View file

@ -1,19 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef LIB_ERROR_H_
#define LIB_ERROR_H_
#include "vm/runtime_entry.h"
namespace dart {
DECLARE_RUNTIME_ENTRY(ConditionTypeError);
DECLARE_RUNTIME_ENTRY(MalformedTypeError);
DECLARE_RUNTIME_ENTRY(TypeCheck);
} // namespace dart
#endif // LIB_ERROR_H_

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "lib/error.h"
#include "vm/bootstrap_natives.h"
#include "vm/exceptions.h"
#include "vm/object_store.h"
@ -51,7 +49,7 @@ DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 2) {
}
// Allocate and throw a new TypeError.
// Allocate and throw a new TypeError or CastError.
// Arg0: index of the token of the failed type check.
// Arg1: src value.
// Arg2: dst type name.

View file

@ -12,6 +12,118 @@ patch class Error {
StackTrace _stackTrace;
}
patch class AssertionError extends Error {
AssertionError._create(
this._failedAssertion, this._url, this._line, this._column);
static _throwNew(int assertionStart, int assertionEnd)
native "AssertionError_throwNew";
String toString() {
return "'$_url': Failed assertion: line $_line pos $_column: "
"'$_failedAssertion' is not true.";
}
final String _failedAssertion;
final String _url;
final int _line;
final int _column;
}
patch class TypeError extends AssertionError {
TypeError._create(String url, int line, int column,
this._srcType, this._dstType, this._dstName,
this._malformedError)
: super._create("is assignable", url, line, column);
static _throwNew(int location,
Object src_value,
String dst_type_name,
String dst_name,
String malformed_error)
native "TypeError_throwNew";
String toString() {
String str = (_malformedError != null) ? _malformedError : "";
if ((_dstName != null) && (_dstName.length > 0)) {
str = "${str}type '$_srcType' is not a subtype of "
"type '$_dstType' of '$_dstName'.";
} else {
str = "${str}malformed type used.";
}
return str;
}
final String _srcType;
final String _dstType;
final String _dstName;
final String _malformedError;
}
patch class CastError extends Error {
CastError._create(this._url, this._line, this._column,
this._srcType, this._dstType, this._dstName,
this._malformedError);
// A CastError is allocated by TypeError._throwNew() when dst_name equals
// Exceptions::kCastErrorDstName.
String toString() {
String str = (_malformedError != null) ? _malformedError : "";
str = "${str}type '$_srcType' is not a subtype of "
"type '$_dstType' in type cast.";
return str;
}
// Fields _url, _line, and _column are only used for debugging purposes.
final String _url;
final int _line;
final int _column;
final String _srcType;
final String _dstType;
final String _dstName;
final String _malformedError;
}
patch class FallThroughError {
FallThroughError._create(this._url, this._line);
static _throwNew(int case_clause_pos) native "FallThroughError_throwNew";
/* patch */ String toString() {
return "'$_url': Switch case fall-through at line $_line.";
}
// These new fields cannot be declared final, because a constructor exists
// in the original version of this patched class.
String _url;
int _line;
}
class _InternalError {
const _InternalError(this._msg);
String toString() => "InternalError: '${_msg}'";
final String _msg;
}
patch class AbstractClassInstantiationError {
AbstractClassInstantiationError._create(
this._className, this._url, this._line);
static _throwNew(int case_clause_pos, String className)
native "AbstractClassInstantiationError_throwNew";
/* patch */ String toString() {
return "Cannot instantiate abstract class $_className: "
"_url '$_url' line $_line";
}
// These new fields cannot be declared final, because a constructor exists
// in the original version of this patched class.
String _url;
int _line;
}
patch class NoSuchMethodError {
// The compiler emits a call to _throwNew when it cannot resolve a static
// method at compile time. The receiver is actually the literal class of the

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "lib/error.h"
#include "vm/bootstrap_natives.h"
#include "vm/exceptions.h"
#include "vm/object_store.h"

View file

@ -653,36 +653,6 @@ DEFINE_RUNTIME_ENTRY(TypeCheck, 6) {
}
// Test whether a formal parameter was defined by a passed-in argument.
// Arg0: formal parameter index as Smi.
// Arg1: formal parameter name as Symbol.
// Arg2: arguments descriptor array.
// Return value: true or false.
DEFINE_RUNTIME_ENTRY(ArgumentDefinitionTest, 3) {
ASSERT(arguments.ArgCount() ==
kArgumentDefinitionTestRuntimeEntry.argument_count());
const Smi& param_index = Smi::CheckedHandle(arguments.ArgAt(0));
const String& param_name = String::CheckedHandle(arguments.ArgAt(1));
ASSERT(param_name.IsSymbol());
const Array& arg_desc_array = Array::CheckedHandle(arguments.ArgAt(2));
ArgumentsDescriptor arg_desc(arg_desc_array);
const intptr_t num_pos_args = arg_desc.PositionalCount();
// Check if the formal parameter is defined by a positional argument.
bool is_defined = num_pos_args > param_index.Value();
if (!is_defined) {
// Check if the formal parameter is defined by a named argument.
const intptr_t num_named_args = arg_desc.NamedCount();
for (intptr_t i = 0; i < num_named_args; i++) {
if (arg_desc.MatchesNameAt(i, param_name)) {
is_defined = true;
break;
}
}
}
arguments.SetReturn(is_defined ? Bool::True() : Bool::False());
}
// Report that the type of the given object is not bool in conditional context.
// Arg0: bad object.
// Return value: none, throws a TypeError.

View file

@ -22,7 +22,6 @@ DECLARE_RUNTIME_ENTRY(AllocateImplicitInstanceClosure);
DECLARE_RUNTIME_ENTRY(AllocateContext);
DECLARE_RUNTIME_ENTRY(AllocateObject);
DECLARE_RUNTIME_ENTRY(AllocateObjectWithBoundsCheck);
DECLARE_RUNTIME_ENTRY(ArgumentDefinitionTest);
DECLARE_RUNTIME_ENTRY(BreakpointRuntimeHandler);
DECLARE_RUNTIME_ENTRY(BreakpointStaticHandler);
DECLARE_RUNTIME_ENTRY(BreakpointReturnHandler);
@ -37,6 +36,9 @@ DECLARE_RUNTIME_ENTRY(InlineCacheMissHandlerThreeArgs);
DECLARE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs);
DECLARE_RUNTIME_ENTRY(InstanceFunctionLookup);
DECLARE_RUNTIME_ENTRY(Instanceof);
DECLARE_RUNTIME_ENTRY(TypeCheck);
DECLARE_RUNTIME_ENTRY(MalformedTypeError);
DECLARE_RUNTIME_ENTRY(ConditionTypeError);
DECLARE_RUNTIME_ENTRY(InstantiateType);
DECLARE_RUNTIME_ENTRY(InstantiateTypeArguments);
DECLARE_RUNTIME_ENTRY(InvokeNoSuchMethodFunction);
@ -54,7 +56,6 @@ DECLARE_RUNTIME_ENTRY(DeoptimizeMaterialize);
DECLARE_RUNTIME_ENTRY(UpdateICDataTwoArgs);
DECLARE_RUNTIME_ENTRY(UpdateFieldCid);
#define DEOPT_REASONS(V) \
V(Unknown) \
V(InstanceGetter) \

View file

@ -496,40 +496,31 @@ RawInstance* Exceptions::NewInstance(const char* class_name) {
}
// Allocate, initialize, and throw a TypeError.
// Allocate, initialize, and throw a TypeError or CastError.
void Exceptions::CreateAndThrowTypeError(intptr_t location,
const String& src_type_name,
const String& dst_type_name,
const String& dst_name,
const String& malformed_error) {
const Array& args = Array::Handle(Array::New(8));
const Array& args = Array::Handle(Array::New(7));
ExceptionType exception_type =
dst_name.Equals(kCastErrorDstName) ? kCast : kType;
// Initialize argument 'failedAssertion'.
// Printing the src_obj value would be possible, but ToString() is expensive
// and not meaningful for all classes, so we just print '$expr instanceof...'.
// Users should look at TypeError.ToString(), which contains more useful
// information than AssertionError.failedAssertion.
String& failed_assertion = String::Handle(String::New("$expr instanceof "));
failed_assertion = String::Concat(failed_assertion, dst_type_name);
args.SetAt(0, failed_assertion);
// Initialize 'url', 'line', and 'column' arguments.
DartFrameIterator iterator;
const Script& script = Script::Handle(GetCallerScript(&iterator));
intptr_t line, column;
script.GetTokenLocation(location, &line, &column);
args.SetAt(1, String::Handle(script.url()));
args.SetAt(2, Smi::Handle(Smi::New(line)));
args.SetAt(3, Smi::Handle(Smi::New(column)));
// Initialize '_url', '_line', and '_column' arguments.
args.SetAt(0, String::Handle(script.url()));
args.SetAt(1, Smi::Handle(Smi::New(line)));
args.SetAt(2, Smi::Handle(Smi::New(column)));
// Initialize argument 'srcType'.
args.SetAt(4, src_type_name);
args.SetAt(5, dst_type_name);
args.SetAt(6, dst_name);
args.SetAt(7, malformed_error);
// Initialize '_srcType', '_dstType', '_dstName', and '_malformedError'.
args.SetAt(3, src_type_name);
args.SetAt(4, dst_type_name);
args.SetAt(5, dst_name);
args.SetAt(6, malformed_error);
// Type errors in the core library may be difficult to diagnose.
// Print type error information before throwing the error when debugging.
@ -550,7 +541,7 @@ void Exceptions::CreateAndThrowTypeError(intptr_t location,
OS::Print("malformed type used.\n");
}
}
// Throw TypeError instance.
// Throw TypeError or CastError instance.
Exceptions::ThrowByType(exception_type, args);
UNREACHABLE();
}
@ -645,7 +636,7 @@ RawObject* Exceptions::Create(ExceptionType type, const Array& arguments) {
case kNoSuchMethod:
library = Library::CoreLibrary();
class_name = &Symbols::NoSuchMethodError();
constructor_name = &String::Handle(Symbols::New("._withType"));
constructor_name = &Symbols::DotWithType();
break;
case kFormat:
library = Library::CoreLibrary();
@ -678,22 +669,27 @@ RawObject* Exceptions::Create(ExceptionType type, const Array& arguments) {
case kAssertion:
library = Library::CoreLibrary();
class_name = &Symbols::AssertionError();
constructor_name = &Symbols::DotCreate();
break;
case kCast:
library = Library::CoreLibrary();
class_name = &Symbols::CastError();
constructor_name = &Symbols::DotCreate();
break;
case kType:
library = Library::CoreLibrary();
class_name = &Symbols::TypeError();
constructor_name = &Symbols::DotCreate();
break;
case kFallThrough:
library = Library::CoreLibrary();
class_name = &Symbols::FallThroughError();
constructor_name = &Symbols::DotCreate();
break;
case kAbstractClassInstantiation:
library = Library::CoreLibrary();
class_name = &Symbols::AbstractClassInstantiationError();
constructor_name = &Symbols::DotCreate();
break;
case kMirroredUncaughtExceptionError:
library = Library::MirrorsLibrary();

View file

@ -7,7 +7,6 @@
#include "vm/flow_graph_compiler.h"
#include "lib/error.h"
#include "vm/ast_printer.h"
#include "vm/dart_entry.h"
#include "vm/deopt_instructions.h"

View file

@ -7,7 +7,6 @@
#include "vm/flow_graph_compiler.h"
#include "lib/error.h"
#include "vm/ast_printer.h"
#include "vm/dart_entry.h"
#include "vm/deopt_instructions.h"

View file

@ -7,7 +7,6 @@
#include "vm/flow_graph_compiler.h"
#include "lib/error.h"
#include "vm/ast_printer.h"
#include "vm/dart_entry.h"
#include "vm/deopt_instructions.h"

View file

@ -7,7 +7,6 @@
#include "vm/flow_graph_compiler.h"
#include "lib/error.h"
#include "vm/ast_printer.h"
#include "vm/dart_entry.h"
#include "vm/deopt_instructions.h"

View file

@ -7,7 +7,6 @@
#include "vm/intermediate_language.h"
#include "lib/error.h"
#include "vm/dart_entry.h"
#include "vm/flow_graph_compiler.h"
#include "vm/locations.h"

View file

@ -7,7 +7,6 @@
#include "vm/intermediate_language.h"
#include "lib/error.h"
#include "vm/dart_entry.h"
#include "vm/flow_graph_compiler.h"
#include "vm/locations.h"

View file

@ -7,7 +7,6 @@
#include "vm/intermediate_language.h"
#include "lib/error.h"
#include "vm/dart_entry.h"
#include "vm/flow_graph_compiler.h"
#include "vm/locations.h"

View file

@ -7,7 +7,6 @@
#include "vm/intermediate_language.h"
#include "lib/error.h"
#include "vm/dart_entry.h"
#include "vm/flow_graph_compiler.h"
#include "vm/locations.h"

View file

@ -146,10 +146,10 @@ const double MegamorphicCache::kLoadFactor = 0.75;
V(CoreLibrary, Object, _as) \
V(CoreLibrary, Object, _instanceOf) \
V(CoreLibrary, _ObjectArray, _ObjectArray.) \
V(CoreLibrary, _AssertionErrorImplementation, _throwNew) \
V(CoreLibrary, _TypeErrorImplementation, _throwNew) \
V(CoreLibrary, _FallThroughErrorImplementation, _throwNew) \
V(CoreLibrary, _AbstractClassInstantiationErrorImplementation, _throwNew) \
V(CoreLibrary, AssertionError, _throwNew) \
V(CoreLibrary, TypeError, _throwNew) \
V(CoreLibrary, FallThroughError, _throwNew) \
V(CoreLibrary, AbstractClassInstantiationError, _throwNew) \
V(CoreLibrary, NoSuchMethodError, _throwNew) \
V(CoreLibrary, int, _throwFormatException) \
V(CoreLibrary, int, _parse) \
@ -1925,6 +1925,15 @@ const char* Class::ApplyPatch(const Class& patch) const {
// new private methods.
Function& func = Function::Handle();
Function& orig_func = Function::Handle();
// Lookup the original implicit constructor, if any.
member_name = Name();
member_name = String::Concat(member_name, Symbols::Dot());
Function& orig_implicit_ctor = Function::Handle(LookupFunction(member_name));
if (!orig_implicit_ctor.IsNull() &&
!orig_implicit_ctor.IsImplicitConstructor()) {
// Not an implicit constructor, but a user declared one.
orig_implicit_ctor = Function::null();
}
const GrowableObjectArray& new_functions = GrowableObjectArray::Handle(
GrowableObjectArray::New(orig_len));
for (intptr_t i = 0; i < orig_len; i++) {
@ -1934,7 +1943,11 @@ const char* Class::ApplyPatch(const Class& patch) const {
if (func.IsNull()) {
// Non-patched function is preserved, all patched functions are added in
// the loop below.
new_functions.Add(orig_func);
// However, an implicitly created constructor should not be preserved if
// the patch provides a constructor or a factory. Wait for now.
if (orig_func.raw() != orig_implicit_ctor.raw()) {
new_functions.Add(orig_func);
}
} else if (!func.HasCompatibleParametersWith(orig_func) &&
!(func.IsFactory() && orig_func.IsConstructor() &&
(func.num_fixed_parameters() + 1 ==
@ -1944,9 +1957,17 @@ const char* Class::ApplyPatch(const Class& patch) const {
}
for (intptr_t i = 0; i < patch_len; i++) {
func ^= patch_list.At(i);
if (func.IsConstructor() || func.IsFactory()) {
// Do not preserve the original implicit constructor, if any.
orig_implicit_ctor = Function::null();
}
func.set_owner(patch_class);
new_functions.Add(func);
}
if (!orig_implicit_ctor.IsNull()) {
// Preserve the original implicit constructor.
new_functions.Add(orig_implicit_ctor);
}
Array& new_list = Array::Handle(Array::MakeArray(new_functions));
SetFunctions(new_list);

View file

@ -34,12 +34,11 @@ class ObjectPointerVisitor;
V(ClosureParameter, ":closure") \
V(PhaseParameter, ":phase") \
V(TypeArgumentsParameter, ":type_arguments") \
V(AssertionError, "_AssertionErrorImplementation") \
V(CastError, "_CastErrorImplementation") \
V(TypeError, "_TypeErrorImplementation") \
V(FallThroughError, "_FallThroughErrorImplementation") \
V(AbstractClassInstantiationError, \
"_AbstractClassInstantiationErrorImplementation") \
V(AssertionError, "AssertionError") \
V(CastError, "CastError") \
V(TypeError, "TypeError") \
V(FallThroughError, "FallThroughError") \
V(AbstractClassInstantiationError, "AbstractClassInstantiationError") \
V(NoSuchMethodError, "NoSuchMethodError") \
V(ThrowNew, "_throwNew") \
V(List, "List") \
@ -218,6 +217,8 @@ class ObjectPointerVisitor;
V(_handleMessage, "_handleMessage") \
V(_SendPortImpl, "_SendPortImpl") \
V(_create, "_create") \
V(DotCreate, "._create") \
V(DotWithType, "._withType") \
V(_id, "_id") \
V(_get_or_create, "_get_or_create") \
V(RangeError, "RangeError") \

View file

@ -448,9 +448,19 @@ Language/13_Libraries_and_Scripts/1_Imports_A03_t66: Fail # co19 issue 463, boun
Language/13_Libraries_and_Scripts/1_Imports_A03_t31: Fail # co19 issue 463
Language/14_Types/8_Parameterized_Types_A02_t01: Fail # co19 issue 463
LibTest/core/AssertionError/line_A01_t02: Fail # co19 issue 479
LibTest/core/Set/intersection_A03_t01: Fail # co19 issue 480
LibTest/core/AssertionError/column_A01_t02: Fail # co19 issue 479
LibTest/core/AssertionError/failedAssertion_A01_t01: Fail # co19 issue 479
LibTest/core/AssertionError/line_A01_t02: Fail # co19 issue 479
LibTest/core/AssertionError/url_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/column_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/dstName_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/dstType_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/failedAssertion_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/line_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/srcType_A01_t01: Fail # co19 issue 479
LibTest/core/TypeError/url_A01_t01: Fail # co19 issue 479
LibTest/core/Strings/concatAll_A04_t01: Fail, OK # checks for ArgumentError. TypeError is ok too. co19 issue 366
LibTest/core/Strings/join_A04_t01: Fail, OK # checks for ArgumentError. TypeError is ok too. co19 issue 366
@ -474,9 +484,12 @@ Language/11_Expressions/15_Method_Invocation/4_Super_Invocation_A04_t03: Pass #
Language/11_Expressions/15_Method_Invocation/4_Super_Invocation_A04_t04: Pass # co19 issues 405 and 463
Language/11_Expressions/15_Method_Invocation/1_Ordinary_Invocation_A05_t06: Pass # co19 issues 405 and 463
Language/11_Expressions/17_Getter_Invocation_A02_t02: Pass # co19 issues 405 and 463
Language/11_Expressions/32_Type_Cast_A05_t01: Fail # co19 issue 463 and issue 5280
Language/11_Expressions/32_Type_Cast_A05_t02: Pass # co19 issue 463 and issue 5280
Language/11_Expressions/32_Type_Cast_A05_t04: Pass # co19 issue 463 and issue 5280
Language/11_Expressions/32_Type_Cast_A05_t01: Fail # co19 issue 463
Language/11_Expressions/32_Type_Cast_A05_t02: Fail # co19 issue 463
Language/11_Expressions/32_Type_Cast_A05_t03: Fail # co19 issue 463
Language/11_Expressions/32_Type_Cast_A05_t04: Fail # co19 issue 463
Language/11_Expressions/32_Type_Cast_A05_t05: Fail # co19 issue 463
Language/12_Statements/09_Switch_A05_t01: Fail # co19 issue 442

View file

@ -56,14 +56,11 @@ class GenericTest {
E e = new E(); // Throws a type error, if type checks are enabled.
} on TypeError catch (error) {
result = 1;
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("generic_test.dart", subs);
Expect.equals(31, error.line); // new B<T>(t); AX does not extend A.
Expect.equals(21, error.column);
// Location of malformed error: T extends A, but AX does not extend A.
Expect.isTrue(error.toString().contains("line 20 pos 9"));
// Location of failed type check: new B<T>(t)/
Expect.isTrue(error.stackTrace.toString().contains(
"generic_test.dart:31:21"));
}
return result;
}

View file

@ -47,8 +47,6 @@ named_parameters_aggregated_test/05: Fail # Compile-time error reported instead
lazy_static3_test: Fail # Issue 3558
type_error_test: Fail # http://dartbug.com/5280
# DartC specific tests that should not be run by the VM
*dartc_test: Skip
*dartc_negative_test: Skip
@ -290,7 +288,7 @@ compile_time_constant_checked3_test/04: Fail, OK
compile_time_constant_checked3_test/05: Fail, OK
compile_time_constant_checked3_test/06: Fail, OK
type_error_test: Fail, OK # VM bug: http://dartbug.com/5280
positional_parameters_type_test: Fail # Triage this.
type_variable_field_initializer_closure_test: Crash # VM bug: issue 8847
closures_initializer_test: Crash # VM bug: issue 8847

View file

@ -7,9 +7,6 @@
# Runtime negative test. No static errors or warnings.
closure_call_wrong_argument_count_negative_test: skip
#argument_definition_test/01: fail # issue 11565 (passing for the wrong reason)
illegal_invocation_test/01: fail # Issue: 11892
# TBF: m([int p = 'String'])
@ -56,6 +53,7 @@ malformed_test/none: fail
# TBF: disallowed in the most recent spec
named_parameters_aggregated_test/03: fail
positional_parameters_type_test: fail
# TBF: non-const superinitializer; 7.6.3 Constant Constructors: The superinitializer that appears, explicitly or implicitly, in the initializer list of a constant constructor must specify a constant constructor of the superclass of the immediately enclosing class.
non_const_super_negative_test: fail

View file

@ -25,22 +25,25 @@ class NamedParametersTypeTest {
acceptFunNumOptBool(funNum); // No static type warning.
} on TypeError catch (error) {
result += 1;
Expect.stringEquals("(num, {b: bool}) => void", error.dstType);
Expect.stringEquals("(num) => void", error.srcType);
var msg = error.toString();
Expect.isTrue(msg.contains("(num, {b: bool}) => void")); // dstType
Expect.isTrue(msg.contains("(num) => void")); // srcType
}
try {
acceptFunNumOptBool(funNumBool); /// static type warning
} on TypeError catch (error) {
result += 10;
Expect.stringEquals("(num, {b: bool}) => void", error.dstType);
Expect.stringEquals("(num, bool) => void", error.srcType);
var msg = error.toString();
Expect.isTrue(msg.contains("(num, {b: bool}) => void")); // dstType
Expect.isTrue(msg.contains("(num, bool) => void")); // srcType
}
try {
acceptFunNumOptBool(funNumOptBoolX); /// static type warning
} on TypeError catch (error) {
result += 100;
Expect.stringEquals("(num, {b: bool}) => void", error.dstType);
Expect.stringEquals("(num, {x: bool}) => void", error.srcType);
var msg = error.toString();
Expect.isTrue(msg.contains("(num, {b: bool}) => void")); // dstType
Expect.isTrue(msg.contains("(num, {x: bool}) => void")); // srcType
}
return result;
}

View file

@ -25,15 +25,23 @@ class NamedParametersTypeTest {
acceptFunNumOptBool(funNum); // No static type warning.
} on TypeError catch (error) {
result += 1;
Expect.stringEquals("(num, [bool]) => void", error.dstType);
Expect.stringEquals("(num) => void", error.srcType);
var msg = error.toString();
Expect.isTrue(msg.contains("'(num, [bool]) => void'")); // dstType
Expect.isTrue(msg.contains("'(num) => void'")); // srcType
Expect.isTrue(msg.contains("'funNumOptBool'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"positional_parameters_type_test.dart:14:35"));
}
try {
acceptFunNumOptBool(funNumBool); /// static type warning
} on TypeError catch (error) {
result += 10;
Expect.stringEquals("(num, [bool]) => void", error.dstType);
Expect.stringEquals("(num, bool) => void", error.srcType);
var msg = error.toString();
Expect.isTrue(msg.contains("'(num, [bool]) => void'")); // dstType
Expect.isTrue(msg.contains("'(num, bool) => void'")); // srcType
Expect.isTrue(msg.contains("'funNumOptBool'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"positional_parameters_type_test.dart:14:35"));
}
try {
acceptFunNumOptBool(funNumOptBoolX); // No static type warning.

View file

@ -22,13 +22,13 @@ class TypeTest {
int result = 0;
try {
var i = "hello" as int; // Throws a CastError
} on TypeError catch (error, stacktrace) {
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("type cast", error.dstName);
checkTopFunction("type_cast_vm_test.dart:24:23", stacktrace);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkTopFunction("type_cast_vm_test.dart:24:23", error.stackTrace);
}
return result;
}
@ -44,7 +44,7 @@ class TypeTest {
a[0] = 0;
a[index()]++; // Type check succeeds, but does not create side effects.
Expect.equals(1, a[0]);
} on TypeError catch (error) {
} catch (error) {
result = 100;
}
return result;
@ -57,13 +57,13 @@ class TypeTest {
}
try {
int i = f("hello" as int); // Throws a CastError
} on TypeError catch (error, stacktrace) {
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("type cast", error.dstName);
checkTopFunction("type_cast_vm_test.dart:59:25", stacktrace);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkTopFunction("type_cast_vm_test.dart:59:25", error.stackTrace);
}
return result;
}
@ -75,13 +75,13 @@ class TypeTest {
}
try {
int i = f("hello");
} on TypeError catch (error, stacktrace) {
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("type cast", error.dstName);
checkTopFunction("type_cast_vm_test.dart:74:16", stacktrace);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkTopFunction("type_cast_vm_test.dart:74:16", error.stackTrace);
}
return result;
}
@ -93,12 +93,12 @@ class TypeTest {
Expect.equals(5, (field as String).length);
try {
field as int; // Throws a CastError
} on TypeError catch (error, stacktrace) {
} catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("type cast", error.dstName);
checkTopFunction("type_cast_vm_test.dart:95:13", stacktrace);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkTopFunction("type_cast_vm_test.dart:95:13", error.stackTrace);
}
return result;
}
@ -111,12 +111,12 @@ class TypeTest {
anyFunction = null as Function; // No error.
try {
var i = f as int; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error, stacktrace) {
} catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("() => dynamic", error.srcType);
Expect.equals("type cast", error.dstName);
checkTopFunction("type_cast_vm_test.dart:113:17", stacktrace);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("() => dynamic")); // srcType
checkTopFunction("type_cast_vm_test.dart:113:17", error.stackTrace);
}
return result;
}

View file

@ -3,8 +3,15 @@
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable_type_checks --no_show_internal_names
// Dart test program testing type checks.
import "package:expect/expect.dart";
class C {
factory C() {
return 1; // Implicit result type is 'C', not int.
}
}
class TypeTest {
static test() {
int result = 0;
@ -12,17 +19,12 @@ class TypeTest {
int i = "hello"; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("i", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(12, error.line);
Expect.equals(15, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'int'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("'i'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:19:15"));
}
return result;
}
@ -53,17 +55,12 @@ class TypeTest {
int i = f("hello"); // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("i", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(49, error.line);
Expect.equals(15, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'int'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("'i'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:51:15"));
}
return result;
}
@ -77,17 +74,12 @@ class TypeTest {
int i = f("hello"); // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("function result", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(74, error.line);
Expect.equals(14, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'int'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("function result")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:71:14"));
}
return result;
}
@ -99,17 +91,12 @@ class TypeTest {
field = "hello"; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("field", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(99, error.line);
Expect.equals(15, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'int'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("'field'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:91:15"));
}
return result;
}
@ -123,17 +110,12 @@ class TypeTest {
int i = f; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result = 1;
Expect.equals("int", error.dstType);
Expect.equals("() => dynamic", error.srcType);
Expect.equals("i", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(123, error.line);
Expect.equals(15, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'int'")); // dstType
Expect.isTrue(msg.contains("'() => dynamic'")); // srcType
Expect.isTrue(msg.contains("'i'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:110:15"));
}
return result;
}
@ -154,17 +136,12 @@ class TypeTest {
acceptObjFunObj(voidFunObj); // Throws a TypeError.
} on TypeError catch (error) {
result = 1;
Expect.equals("(Object) => Object", error.dstType);
Expect.equals("(Object) => void", error.srcType);
Expect.equals("objFunObj", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(145, error.line);
Expect.equals(33, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'(Object) => Object'")); // dstType
Expect.isTrue(msg.contains("'(Object) => void'")); // srcType
Expect.isTrue(msg.contains("'objFunObj'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:127:33"));
}
return result;
}
@ -188,17 +165,12 @@ class TypeTest {
acceptFunNum(funString); // Throws an error.
} on TypeError catch (error) {
result = 1;
Expect.equals("(num) => void", error.dstType);
Expect.equals("(String) => void", error.srcType);
Expect.equals("funNum", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(175, error.line);
Expect.equals(28, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'(num) => void'")); // dstType
Expect.isTrue(msg.contains("'(String) => void'")); // srcType
Expect.isTrue(msg.contains("'funNum'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:152:28"));
}
return result;
}
@ -209,145 +181,100 @@ class TypeTest {
bool i = !"hello"; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(209, error.line);
Expect.equals(17, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:181:17"));
}
try {
while ("hello") {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(225, error.line);
Expect.equals(14, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:192:14"));
}
try {
do {} while ("hello"); // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(241, error.line);
Expect.equals(20, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:203:20"));
}
try {
for (;"hello";) {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(257, error.line);
Expect.equals(13, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:214:13"));
}
try {
int i = "hello" ? 1 : 0; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(273, error.line);
Expect.equals(15, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:225:15"));
}
try {
if ("hello") {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(289, error.line);
Expect.equals(11, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:236:11"));
}
try {
if ("hello" || false) {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(305, error.line);
Expect.equals(11, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:247:11"));
}
try {
if (false || "hello") {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("String", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(321, error.line);
Expect.equals(20, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'String'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:258:20"));
}
try {
if (null) {}; // Throws a TypeError if type checks are enabled.
} on TypeError catch (error) {
result++;
Expect.equals("bool", error.dstType);
Expect.equals("Null", error.srcType);
Expect.equals("boolean expression", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(337, error.line);
Expect.equals(11, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'bool'")); // dstType
Expect.isTrue(msg.contains("'Null'")); // srcType
Expect.isTrue(msg.contains("boolean expression")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:269:11"));
}
return result;
}
@ -359,17 +286,12 @@ class TypeTest {
var x = new C();
} on TypeError catch (error) {
result++;
Expect.equals("C", error.dstType);
Expect.equals("int", error.srcType);
Expect.equals("function result", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(560, error.line);
Expect.equals(12, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'C'")); // dstType
Expect.isTrue(msg.contains("'int'")); // srcType
Expect.isTrue(msg.contains("function result")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:11:12"));
}
return result;
}
@ -392,49 +314,34 @@ class TypeTest {
List<int> ai = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<int>", error.dstType);
Expect.equals("List<Object>", error.srcType);
Expect.equals("ai", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(392, error.line);
Expect.equals(24, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<int>'")); // dstType
Expect.isTrue(msg.contains("'List<Object>'")); // srcType
Expect.isTrue(msg.contains("'ai'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:314:24"));
}
try {
List<num> an = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<num>", error.dstType);
Expect.equals("List<Object>", error.srcType);
Expect.equals("an", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(408, error.line);
Expect.equals(24, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<num>'")); // dstType
Expect.isTrue(msg.contains("'List<Object>'")); // srcType
Expect.isTrue(msg.contains("'an'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:325:24"));
}
try {
List<String> as = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<String>", error.dstType);
Expect.equals("List<Object>", error.srcType);
Expect.equals("as", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(424, error.line);
Expect.equals(27, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<String>'")); // dstType
Expect.isTrue(msg.contains("'List<Object>'")); // srcType
Expect.isTrue(msg.contains("'as'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:336:27"));
}
}
{
@ -447,17 +354,12 @@ class TypeTest {
List<String> as = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<String>", error.dstType);
Expect.equals("List<int>", error.srcType);
Expect.equals("as", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(447, error.line);
Expect.equals(27, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<String>'")); // dstType
Expect.isTrue(msg.contains("'List<int>'")); // srcType
Expect.isTrue(msg.contains("'as'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:354:27"));
}
}
{
@ -468,34 +370,24 @@ class TypeTest {
List<int> ai = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<int>", error.dstType);
Expect.equals("List<num>", error.srcType);
Expect.equals("ai", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(468, error.line);
Expect.equals(24, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<int>'")); // dstType
Expect.isTrue(msg.contains("'List<num>'")); // srcType
Expect.isTrue(msg.contains("'ai'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:370:24"));
}
List<num> an = a;
try {
List<String> as = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<String>", error.dstType);
Expect.equals("List<num>", error.srcType);
Expect.equals("as", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(485, error.line);
Expect.equals(27, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<String>'")); // dstType
Expect.isTrue(msg.contains("'List<num>'")); // srcType
Expect.isTrue(msg.contains("'as'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:382:27"));
}
}
{
@ -506,33 +398,23 @@ class TypeTest {
List<int> ai = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<int>", error.dstType);
Expect.equals("List<String>", error.srcType);
Expect.equals("ai", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(506, error.line);
Expect.equals(24, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<int>'")); // dstType
Expect.isTrue(msg.contains("'List<String>'")); // srcType
Expect.isTrue(msg.contains("'ai'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:398:24"));
}
try {
List<num> an = a;
} on TypeError catch (error) {
result++;
Expect.equals("List<num>", error.dstType);
Expect.equals("List<String>", error.srcType);
Expect.equals("an", error.dstName);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("type_vm_test.dart", subs);
Expect.equals(522, error.line);
Expect.equals(24, error.column);
var msg = error.toString();
Expect.isTrue(msg.contains("'List<num>'")); // dstType
Expect.isTrue(msg.contains("'List<String>'")); // srcType
Expect.isTrue(msg.contains("'an'")); // dstName
Expect.isTrue(error.stackTrace.toString().contains(
"type_vm_test.dart:409:24"));
}
List<String> as = a;
}
@ -554,14 +436,6 @@ class TypeTest {
}
}
class C {
factory C() {
return 1; // Implicit result type is 'C', not int.
}
}
main() {
TypeTest.testMain();
}

View file

@ -6,7 +6,6 @@
javascript_int_overflow_literal_test/01: fail, ok
# https://code.google.com/p/dart/issues/detail?id=11665
standalone/assert_test: fail
standalone/io/directory_invalid_arguments_test: fail
standalone/io/file_constructor_test: fail
standalone/io/file_fuzz_test: fail

View file

@ -2,7 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--enable_asserts
// Dart test program testing assert statements.
import "package:expect/expect.dart";
class AssertTest {
@ -11,15 +13,9 @@ class AssertTest {
assert(false);
Expect.fail("Assertion 'false' didn't fail.");
} on AssertionError catch (error) {
Expect.equals("false", error.failedAssertion);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("assert_test.dart", subs);
Expect.equals(11, error.line);
Expect.equals(14, error.column);
Expect.isTrue(error.toString().contains("'false'"));
Expect.isTrue(error.stackTrace.toString().contains(
"assert_test.dart:13:14"));
}
}
static testClosure() {
@ -27,15 +23,9 @@ class AssertTest {
assert(() => false);
Expect.fail("Assertion '() => false' didn't fail.");
} on AssertionError catch (error) {
Expect.equals("() => false", error.failedAssertion);
int pos = error.url.lastIndexOf("/", error.url.length);
if (pos == -1) {
pos = error.url.lastIndexOf("\\", error.url.length);
}
String subs = error.url.substring(pos + 1, error.url.length);
Expect.equals("assert_test.dart", subs);
Expect.equals(27, error.line);
Expect.equals(14, error.column);
Expect.isTrue(error.toString().contains("'() => false'"));
Expect.isTrue(error.stackTrace.toString().contains(
"assert_test.dart:23:14"));
}
}