From 1d567c888fa58d0a6c399e17dfd4e421cd3ba5f6 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Thu, 8 Dec 2022 17:07:33 +0000 Subject: [PATCH] [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 Commit-Queue: Daco Harkes --- runtime/lib/errors.cc | 2 +- runtime/vm/exceptions.cc | 17 ++++------------- runtime/vm/exceptions.h | 1 - runtime/vm/object.cc | 4 ++-- runtime/vm/runtime_entry.cc | 2 +- runtime/vm/symbols.h | 1 - sdk/lib/_internal/vm/lib/errors_patch.dart | 6 +++--- 7 files changed, 11 insertions(+), 22 deletions(-) diff --git a/runtime/lib/errors.cc b/runtime/lib/errors.cc index 3ef30797059..8534c748f7f 100644 --- a/runtime/lib/errors.cc +++ b/runtime/lib/errors.cc @@ -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. diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc index 7899d72a4b2..16aa4749d46 100644 --- a/runtime/vm/exceptions.cc +++ b/runtime/vm/exceptions.cc @@ -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(); diff --git a/runtime/vm/exceptions.h b/runtime/vm/exceptions.h index a752c95716f..d7b73672c52 100644 --- a/runtime/vm/exceptions.h +++ b/runtime/vm/exceptions.h @@ -64,7 +64,6 @@ class Exceptions : AllStatic { kNullThrown, kIsolateSpawn, kAssertion, - kCast, kType, kAbstractClassInstantiation, kCyclicInitializationError, diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 61741448755..05c95bb94a4 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -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( diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc index 561cb826456..163a3774168 100644 --- a/runtime/vm/runtime_entry.cc +++ b/runtime/vm/runtime_entry.cc @@ -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; } diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h index e3bb1b766af..b63a4003ee8 100644 --- a/runtime/vm/symbols.h +++ b/runtime/vm/symbols.h @@ -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") \ diff --git a/sdk/lib/_internal/vm/lib/errors_patch.dart b/sdk/lib/_internal/vm/lib/errors_patch.dart index 3e1baffe8c3..30bf59fd285 100644 --- a/sdk/lib/_internal/vm/lib/errors_patch.dart +++ b/sdk/lib/_internal/vm/lib/errors_patch.dart @@ -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; }