Skip to content

Commit

Permalink
[vm] Remove use of CastError
Browse files Browse the repository at this point in the history
`CastError` is replaced by `TypeError`.

Also makes the fields of TypeError nullable. See:
#49279

TEST=build SDK and run default suites.

Bug: #49529
Change-Id: I7e880ff2d8b18c4bffdd7a942efd743244a12734
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274381
Reviewed-by: Tess Strickland <[email protected]>
Commit-Queue: Daco Harkes <[email protected]>
  • Loading branch information
dcharkes authored and Commit Queue committed Dec 8, 2022
1 parent 96e2e55 commit 1d567c8
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion runtime/lib/errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 4 additions & 13 deletions runtime/vm/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion runtime/vm/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Exceptions : AllStatic {
kNullThrown,
kIsolateSpawn,
kAssertion,
kCast,
kType,
kAbstractClassInstantiation,
kCyclicInitializationError,
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/runtime_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion runtime/vm/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") \
Expand Down
6 changes: 3 additions & 3 deletions sdk/lib/_internal/vm/lib/errors_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1d567c8

Please sign in to comment.