[vm] Remove use of CastError

`CastError` is replaced by `TypeError`.

Also makes the fields of TypeError nullable. See:
https://github.com/dart-lang/sdk/issues/49279

TEST=build SDK and run default suites.

Bug: https://github.com/dart-lang/sdk/issues/49529
Change-Id: I7e880ff2d8b18c4bffdd7a942efd743244a12734
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274381
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes
2022-12-08 17:07:33 +00:00
committed by Commit Queue
parent 96e2e55300
commit 1d567c888f
7 changed files with 11 additions and 22 deletions
+1 -1
View File
@@ -144,7 +144,7 @@ DEFINE_NATIVE_ENTRY(AssertionError_throwNewSource, 0, 4) {
return Object::null();
}
// Allocate and throw a new TypeError or CastError.
// Allocate and throw a new TypeError.
// Arg0: index of the token of the failed type check.
// Arg1: src value.
// Arg2: dst type.
+4 -13
View File
@@ -865,8 +865,7 @@ InstancePtr Exceptions::NewInstance(const char* class_name) {
return Instance::New(cls);
}
// Allocate, initialize, and throw a TypeError or CastError.
// If error_msg is not null, throw a TypeError, even for a type cast.
// Allocate, initialize, and throw a TypeError.
void Exceptions::CreateAndThrowTypeError(TokenPosition location,
const AbstractType& src_type,
const AbstractType& dst_type,
@@ -876,8 +875,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
Zone* zone = thread->zone();
const Array& args = Array::Handle(zone, Array::New(4));
ExceptionType exception_type =
(dst_name.ptr() == Symbols::InTypeCast().ptr()) ? kCast : kType;
ExceptionType exception_type = kType;
DartFrameIterator iterator(thread,
StackFrameIterator::kNoCrossThreadIteration);
@@ -908,9 +906,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
pieces.Add(Symbols::TypeQuote());
pieces.Add(String::Handle(zone, dst_type.UserVisibleName()));
pieces.Add(Symbols::SingleQuote());
if (exception_type == kCast) {
pieces.Add(dst_name);
} else if (dst_name.Length() > 0) {
if (dst_name.Length() > 0) {
pieces.Add(Symbols::SpaceOfSpace());
pieces.Add(Symbols::SingleQuote());
pieces.Add(dst_name);
@@ -944,7 +940,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
THR_Print("%s\n", error_msg.ToCString());
}
// Throw TypeError or CastError instance.
// Throw TypeError instance.
Exceptions::ThrowByType(exception_type, args);
UNREACHABLE();
}
@@ -1151,11 +1147,6 @@ ObjectPtr Exceptions::Create(ExceptionType type, const Array& arguments) {
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();
-1
View File
@@ -64,7 +64,6 @@ class Exceptions : AllStatic {
kNullThrown,
kIsolateSpawn,
kAssertion,
kCast,
kType,
kAbstractClassInstantiation,
kCyclicInitializationError,
+2 -2
View File
@@ -20019,11 +20019,11 @@ Instance checks (e is T) in strong checking mode in a legacy or opted-in lib:
Casts (e as T) in weak checking mode in a legacy or opted-in library:
If LEGACY_SUBTYPE(S, T) then e as T evaluates to v.
Otherwise a CastError is thrown.
Otherwise a TypeError is thrown.
Casts (e as T) in strong checking mode in a legacy or opted-in library:
If NNBD_SUBTYPE(S, T) then e as T evaluates to v.
Otherwise a CastError is thrown.
Otherwise a TypeError is thrown.
*/
bool Instance::IsInstanceOf(
+1 -1
View File
@@ -169,7 +169,7 @@ static void NullErrorHelper(Zone* zone,
args.SetAt(
3, String::Handle(
zone, String::New("Null check operator used on a null value")));
Exceptions::ThrowByType(Exceptions::kCast, args);
Exceptions::ThrowByType(Exceptions::kType, args);
return;
}
-1
View File
@@ -32,7 +32,6 @@ class ObjectPointerVisitor;
V(BoundsCheckForPartialInstantiation, "_boundsCheckForPartialInstantiation") \
V(ByteData, "ByteData") \
V(Capability, "Capability") \
V(CastError, "_CastError") \
V(CheckLoaded, "_checkLoaded") \
V(Class, "Class") \
V(ClassID, "ClassID") \
+3 -3
View File
@@ -106,9 +106,9 @@ class _TypeError extends Error implements TypeError, CastError {
String toString() => _message;
final String _url;
final int _line;
final int _column;
final String? _url;
final int? _line;
final int? _column;
final String _message;
}