Skip to content

Commit 1d567c8

Browse files
dcharkesCommit Queue
authored and
Commit Queue
committed
[vm] Remove use of CastError
`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]>
1 parent 96e2e55 commit 1d567c8

File tree

7 files changed

+11
-22
lines changed

7 files changed

+11
-22
lines changed

runtime/lib/errors.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ DEFINE_NATIVE_ENTRY(AssertionError_throwNewSource, 0, 4) {
144144
return Object::null();
145145
}
146146

147-
// Allocate and throw a new TypeError or CastError.
147+
// Allocate and throw a new TypeError.
148148
// Arg0: index of the token of the failed type check.
149149
// Arg1: src value.
150150
// Arg2: dst type.

runtime/vm/exceptions.cc

+4-13
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,7 @@ InstancePtr Exceptions::NewInstance(const char* class_name) {
865865
return Instance::New(cls);
866866
}
867867

868-
// Allocate, initialize, and throw a TypeError or CastError.
869-
// If error_msg is not null, throw a TypeError, even for a type cast.
868+
// Allocate, initialize, and throw a TypeError.
870869
void Exceptions::CreateAndThrowTypeError(TokenPosition location,
871870
const AbstractType& src_type,
872871
const AbstractType& dst_type,
@@ -876,8 +875,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
876875
Zone* zone = thread->zone();
877876
const Array& args = Array::Handle(zone, Array::New(4));
878877

879-
ExceptionType exception_type =
880-
(dst_name.ptr() == Symbols::InTypeCast().ptr()) ? kCast : kType;
878+
ExceptionType exception_type = kType;
881879

882880
DartFrameIterator iterator(thread,
883881
StackFrameIterator::kNoCrossThreadIteration);
@@ -908,9 +906,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
908906
pieces.Add(Symbols::TypeQuote());
909907
pieces.Add(String::Handle(zone, dst_type.UserVisibleName()));
910908
pieces.Add(Symbols::SingleQuote());
911-
if (exception_type == kCast) {
912-
pieces.Add(dst_name);
913-
} else if (dst_name.Length() > 0) {
909+
if (dst_name.Length() > 0) {
914910
pieces.Add(Symbols::SpaceOfSpace());
915911
pieces.Add(Symbols::SingleQuote());
916912
pieces.Add(dst_name);
@@ -944,7 +940,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
944940
THR_Print("%s\n", error_msg.ToCString());
945941
}
946942

947-
// Throw TypeError or CastError instance.
943+
// Throw TypeError instance.
948944
Exceptions::ThrowByType(exception_type, args);
949945
UNREACHABLE();
950946
}
@@ -1151,11 +1147,6 @@ ObjectPtr Exceptions::Create(ExceptionType type, const Array& arguments) {
11511147
class_name = &Symbols::AssertionError();
11521148
constructor_name = &Symbols::DotCreate();
11531149
break;
1154-
case kCast:
1155-
library = Library::CoreLibrary();
1156-
class_name = &Symbols::CastError();
1157-
constructor_name = &Symbols::DotCreate();
1158-
break;
11591150
case kType:
11601151
library = Library::CoreLibrary();
11611152
class_name = &Symbols::TypeError();

runtime/vm/exceptions.h

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class Exceptions : AllStatic {
6464
kNullThrown,
6565
kIsolateSpawn,
6666
kAssertion,
67-
kCast,
6867
kType,
6968
kAbstractClassInstantiation,
7069
kCyclicInitializationError,

runtime/vm/object.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -20019,11 +20019,11 @@ Instance checks (e is T) in strong checking mode in a legacy or opted-in lib:
2001920019

2002020020
Casts (e as T) in weak checking mode in a legacy or opted-in library:
2002120021
If LEGACY_SUBTYPE(S, T) then e as T evaluates to v.
20022-
Otherwise a CastError is thrown.
20022+
Otherwise a TypeError is thrown.
2002320023

2002420024
Casts (e as T) in strong checking mode in a legacy or opted-in library:
2002520025
If NNBD_SUBTYPE(S, T) then e as T evaluates to v.
20026-
Otherwise a CastError is thrown.
20026+
Otherwise a TypeError is thrown.
2002720027
*/
2002820028

2002920029
bool Instance::IsInstanceOf(

runtime/vm/runtime_entry.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void NullErrorHelper(Zone* zone,
169169
args.SetAt(
170170
3, String::Handle(
171171
zone, String::New("Null check operator used on a null value")));
172-
Exceptions::ThrowByType(Exceptions::kCast, args);
172+
Exceptions::ThrowByType(Exceptions::kType, args);
173173
return;
174174
}
175175

runtime/vm/symbols.h

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ObjectPointerVisitor;
3232
V(BoundsCheckForPartialInstantiation, "_boundsCheckForPartialInstantiation") \
3333
V(ByteData, "ByteData") \
3434
V(Capability, "Capability") \
35-
V(CastError, "_CastError") \
3635
V(CheckLoaded, "_checkLoaded") \
3736
V(Class, "Class") \
3837
V(ClassID, "ClassID") \

sdk/lib/_internal/vm/lib/errors_patch.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class _TypeError extends Error implements TypeError, CastError {
106106

107107
String toString() => _message;
108108

109-
final String _url;
110-
final int _line;
111-
final int _column;
109+
final String? _url;
110+
final int? _line;
111+
final int? _column;
112112
final String _message;
113113
}
114114

0 commit comments

Comments
 (0)