Revert "Deprecate outdated errors, drop `CastError` and `NullThrownError`."
This reverts commit 0f3dea33f9a7f97a6b90b18025eea551841227cd.
Reason for revert: breaks dart->engine roller as flutter still uses NullThrownError, fails analysis step
Original change's description:
> Deprecate outdated errors, drop `CastError` and `NullThrownError`.
>
> Both `CastError` and `NullThrownError` becomes just (deprecated) aliases for `TypeError`.
>
> `FallThroughError` becomes deprecated. Fall-through was made a compile-time error in Dart 2.0, the error should no longer be used.
>
> `CyclicInitializationError` is deprecated. Null safe Dart doesn't specify which error a late initialization error throws. We use internal errors now.
>
> These errors should not be needed in sound null-safe mode (if they are even needed now), and so should be removed in Dart 3.0.
>
> TEST= No new tests, should not change behavior in a significant way.
>
> Bug: https://github.com/dart-lang/sdk/issues/49141
> Change-Id: I636e9a0d0c32021d40bb819a88a1f57db6efc5a9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247384
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Brian Quinlan <bquinlan@google.com>
> Commit-Queue: Lasse Nielsen <lrn@google.com>
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: https://github.com/dart-lang/sdk/issues/49141
Change-Id: I1b2802ec69fe654525e683527ff3554ff972f0c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/248741
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
diff --git a/pkg/test_runner/lib/src/static_error.dart b/pkg/test_runner/lib/src/static_error.dart
index c24e8f8..fdabb44 100644
--- a/pkg/test_runner/lib/src/static_error.dart
+++ b/pkg/test_runner/lib/src/static_error.dart
@@ -312,7 +312,7 @@
return false;
}
- throw UnsupportedError("Unsupported source: ${source.name}");
+ throw FallThroughError();
}
String toString() {
diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h
index 80e135e..f0fe6a8 100644
--- a/runtime/vm/symbols.h
+++ b/runtime/vm/symbols.h
@@ -211,7 +211,7 @@
V(NoSuchMethod, "noSuchMethod") \
V(NoSuchMethodError, "NoSuchMethodError") \
V(Null, "Null") \
- V(NullThrownError, "_NullThrownError") \
+ V(NullThrownError, "NullThrownError") \
V(Number, "num") \
V(Object, "Object") \
V(ObjectPool, "ObjectPool") \
diff --git a/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart b/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart
index 49c92c7..1eed466 100644
--- a/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart
+++ b/sdk/lib/_internal/js_dev_runtime/private/js_helper.dart
@@ -692,7 +692,7 @@
abstract class JavaScriptIndexingBehavior<E> extends JSMutableIndexable<E> {}
/// Thrown by type assertions that fail.
-class TypeErrorImpl extends Error implements TypeError {
+class TypeErrorImpl extends Error implements TypeError, CastError {
final String _message;
TypeErrorImpl(this._message);
diff --git a/sdk/lib/_internal/js_shared/lib/rti.dart b/sdk/lib/_internal/js_shared/lib/rti.dart
index ca9ab8f..b7c9881 100644
--- a/sdk/lib/_internal/js_shared/lib/rti.dart
+++ b/sdk/lib/_internal/js_shared/lib/rti.dart
@@ -1073,7 +1073,7 @@
String toString() => _message;
}
-class _TypeError extends _Error implements TypeError {
+class _TypeError extends _Error implements TypeError, CastError {
_TypeError.fromMessage(String message) : super('TypeError: $message');
factory _TypeError.forType(object, String type) {
diff --git a/sdk/lib/_internal/vm/lib/errors_patch.dart b/sdk/lib/_internal/vm/lib/errors_patch.dart
index 0c448da..05b0afa 100644
--- a/sdk/lib/_internal/vm/lib/errors_patch.dart
+++ b/sdk/lib/_internal/vm/lib/errors_patch.dart
@@ -95,7 +95,7 @@
final Object? message;
}
-class _TypeError extends Error implements TypeError {
+class _TypeError extends Error implements TypeError, CastError {
@pragma("vm:entry-point")
_TypeError._create(this._url, this._line, this._column, this._message);
@@ -112,7 +112,7 @@
final String _message;
}
-class _CastError extends Error implements TypeError {
+class _CastError extends Error implements CastError, TypeError {
@pragma("vm:entry-point")
_CastError._create(this._url, this._line, this._column, this._errorMsg);
@@ -128,12 +128,6 @@
final String _errorMsg;
}
-class _NullThrownError extends Error implements NullThrownError {
- @pragma("vm:entry-point")
- _NullThrownError();
- String toString() => "Throw of null.";
-}
-
@patch
class FallThroughError {
@patch
diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart
index 664777c..bdb1a01 100644
--- a/sdk/lib/core/errors.dart
+++ b/sdk/lib/core/errors.dart
@@ -140,14 +140,17 @@
/// Error thrown by the runtime system when a cast operation fails.
@Deprecated("Use TypeError instead")
-typedef CastError = TypeError;
+class CastError extends Error {}
/// Error thrown when attempting to throw `null`.
///
/// In null safe code, you are statically disallowed from throwing `null`,
/// so this error will go away when non-null safe code stops being supported.
-@Deprecated("Use TypeError instead")
-typedef NullThrownError = TypeError;
+class NullThrownError extends Error {
+ @pragma("vm:entry-point")
+ NullThrownError();
+ String toString() => "Throw of null.";
+}
/// Error thrown when a function is passed an unacceptable argument.
class ArgumentError extends Error {
@@ -450,12 +453,10 @@
/// Error thrown when control reaches the end of a switch case.
///
-/// The Dart specification required this error to be thrown when
+/// The Dart specification requires this error to be thrown when
/// control reaches the end of a switch case (except the last case
/// of a switch) without meeting a break or similar end of the control
/// flow.
-/// Fallthrough has been made a compile-time error in Dart 2.0.
-@Deprecated("No longer relevant in Dart 2.0")
class FallThroughError extends Error {
FallThroughError();
@pragma("vm:entry-point")
@@ -607,8 +608,8 @@
/// Error thrown when a lazily initialized variable cannot be initialized.
///
/// This is no longer used in null safe Dart code and is replaced by late
-/// variables which do not specify the error they throw when misused.
-@Deprecated("Not needed by null safe code")
+/// variables and `LateInitializationError`.
+// TODO: Deprecate?
class CyclicInitializationError extends Error {
final String? variableName;
@pragma("vm:entry-point")
diff --git a/tests/language/nnbd/syntax/null_assertion_ambiguous_test.dart b/tests/language/nnbd/syntax/null_assertion_ambiguous_test.dart
index c94b2ca..8cb6e4a 100644
--- a/tests/language/nnbd/syntax/null_assertion_ambiguous_test.dart
+++ b/tests/language/nnbd/syntax/null_assertion_ambiguous_test.dart
@@ -6,8 +6,8 @@
import 'dart:async';
class C {
- C operator *(int? other) => this;
- Object? operator -() => null;
+ C operator*(int? other) => this;
+ Object? operator-() => null;
}
// Test ambiguous cases of trailing "!" syntax. Where possible, we verify that
@@ -18,10 +18,11 @@
// `throw a!` means `throw (a!)`, not `(throw a)!`. Since it's a compile-time
// error for a thrown expression to be potentially nullable, this is
// sufficient to verify that the compiler has resolved the ambiguity
- // correctly.
+ // correctly. We check the runtime behavior by verifying that the error that
+ // is thrown is not `NullThrownError`.
Expect.throws(() {
- throw a!;
- });
+ throw a!;
+ }, (error) => error is! NullThrownError);
// `() => a!` means `() => (a!)`, not `(() => a)!`. We check the compile-time
// behavior by trying to assign to a function returning non-null. We check
@@ -30,7 +31,7 @@
var x1 = () => a!;
Object Function() x2 = x1;
Expect.throws(() {
- x1();
+ x1();
});
// `x = a!` means `x = (a!)`, not `(x = a)!`. We check the compile-time
@@ -39,11 +40,11 @@
// assignment occurs.
Object x3 = 0;
Expect.throws(() {
- x3 = a!;
+ x3 = a!;
});
var x4 = 0 as Object?;
Expect.throws(() {
- x4 = a!;
+ x4 = a!;
});
Expect.equals(x4, 0);
@@ -65,7 +66,7 @@
var x7 = new C();
i = null;
Expect.throws(() {
- x7 * i!;
+ x7 * i!;
});
// `-x!` means `-(x!)`, not `(-x)!`. We check the compile-time behavior by