-
Notifications
You must be signed in to change notification settings - Fork 213
Deprecate CastError and use TypeError uniformly instead #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One issue is that If we are doing things, I would prefer that we make |
I'm fine with this. |
We agreed to do as @lrhn proposes, he will shepherd the breaking change. |
The plan is:
I decided against making either of |
This makes CastError implement TypeError, and changes all test expectations to look for TypeError. A followup CL will deprecate CastError. Bug: dart-lang/language#787 Bug: #34097 Change-Id: I7102c6260901317572d2df08c4be9c4c48197688 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138670 Reviewed-by: Bob Nystrom <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]>
This has landed. |
Developers don't typically write code that depends on the distinction between
CastError
andTypeError
. I suspect many developers don't have a clear model of which one is thrown when. Either the code crashed or it didn't. Errors tend to be handled uniformly, for example, they are logged and then the program tries to recover from a general failure.Having two almost identical Errors creates a burden in code size and library complexity.
dart2js has many small 'helper' functions to implement the checks efficiently.
The following code from
sdk/lib/_internal/js_runtime/lib/rti.dart
illustrates the duplication:Note that the only difference is in the error object
_CastError
vs_TypeError
.These methods are called from many places in the program, either indirectly through type objects representing
String*
andString?
, or directly in optimized code.The whole system of specialization is replicated for two exception types. Simplification via passing in an 'isTypeError' flag has an impact proportional to the application size that is unacceptable to our customers.
I propose that
CastError
becomes an interface that is implemented byTypeError
, and removed at a future major revision.The text was updated successfully, but these errors were encountered: