Deprecate FallThroughError.

The error has not been thrown since Dart 2.0,
where being able to reach the end of a switch case
became a compile-time error.

TEST=Removes tests depending on discontinued behavior.

Change-Id: I76292e7c73f2b3aaf071bbb290e97db493b75477
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261860
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2022-10-25 12:25:35 +00:00 committed by Commit Queue
parent f524ec74ce
commit c13676f2b7
13 changed files with 28 additions and 119 deletions

View file

@ -70,6 +70,11 @@
[#34233]: https://github.com/dart-lang/sdk/issues/34233
[`DEFAULT_BUFFER_SIZE`]: https://api.dart.dev/stable/2.17.6/dart-convert/JsonUtf8Encoder/DEFAULT_BUFFER_SIZE-constant.html
#### `dart:core`
- Deprecated `FallThroughError`. Has not been thrown since Dart 2.0.
See [#24233][].
#### `dart:developer`
- **Breaking change** [#34233][]: The previously deprecated APIs

View file

@ -312,7 +312,7 @@ class StaticError implements Comparable<StaticError> {
return false;
}
throw FallThroughError();
throw UnsupportedError("ErrorSource ${source.name}");
}
String toString() {

View file

@ -68,7 +68,7 @@ Future<List<String>> findValidTests(List<String> directories, bool nnbd) async {
'The following tests were filtered due to using blacklisted things:');
for (int i = 0; i < testFiles.length; ++i) {
testFiles[i] = path.relative(testFiles[i], from: thisDir);
testFiles[i] = path.relative(testFiles[i], from: thisDirectory);
}
if (File(tempFile).existsSync()) {
File(tempFile).deleteSync();

View file

@ -2555,7 +2555,6 @@
"../../../tests/language/switch/case_expression_with_assignment_runtime_test.dart",
"../../../tests/language/switch/case_runtime_test.dart",
"../../../tests/language/switch/case_static_const_test.dart",
"../../../tests/language/switch/fallthru_runtime_test.dart",
"../../../tests/language/switch/infinite_switch_label_test.dart",
"../../../tests/language/switch/label2_test.dart",
"../../../tests/language/switch/label_test.dart",
@ -5888,7 +5887,6 @@
"../../../tests/language_2/switch/case_expression_with_assignment_runtime_test.dart",
"../../../tests/language_2/switch/case_runtime_test.dart",
"../../../tests/language_2/switch/case_static_const_test.dart",
"../../../tests/language_2/switch/fallthru_runtime_test.dart",
"../../../tests/language_2/switch/infinite_switch_label_test.dart",
"../../../tests/language_2/switch/label2_test.dart",
"../../../tests/language_2/switch/label_test.dart",

View file

@ -1143,11 +1143,6 @@ ObjectPtr Exceptions::Create(ExceptionType type, const Array& arguments) {
class_name = &Symbols::TypeError();
constructor_name = &Symbols::DotCreate();
break;
case kFallThrough:
library = Library::CoreLibrary();
class_name = &Symbols::FallThroughError();
constructor_name = &Symbols::DotCreate();
break;
case kAbstractClassInstantiation:
library = Library::CoreLibrary();
class_name = &Symbols::AbstractClassInstantiationError();

View file

@ -66,7 +66,6 @@ class Exceptions : AllStatic {
kAssertion,
kCast,
kType,
kFallThrough,
kAbstractClassInstantiation,
kCyclicInitializationError,
kCompileTimeError,

View file

@ -451,12 +451,14 @@ class IndexError extends ArgumentError implements RangeError {
}
}
/// Error thrown when control reaches the end of a switch case.
/// Error previously thrown when control reaches the end of a switch case.
///
/// 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.
/// The pre-2.0 Dart specification required this error to be thrown when
/// control reached the end of a switch case (except the last case
/// of a switch) without meeting a `break` or other control flow operators.
/// That kind of fall-through was made a compile-time error Dart 2.0,
/// so this error no longer thrown.
@Deprecated("No longer relevant in Dart 2.0")
class FallThroughError extends Error {
FallThroughError();
@pragma("vm:entry-point")

View file

@ -14,17 +14,12 @@ import "package:expect/expect.dart";
class EmptyBlockCaseTest {
static testMain() {
var exception = null;
try {
switch (1) {
case 1: /*@compile-error=unspecified*/
{}
case 2:
Expect.equals(true, false);
}
} on FallThroughError catch (e) {
exception = e;
switch (1) {
case 1: /*@compile-error=unspecified*/
{}
case 2:
Expect.equals(true, false);
}
Expect.equals(true, exception != null);
}
}

View file

@ -1,38 +0,0 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Check that FallThroughError is thrown if switch clause does not terminate.
// VMOptions=
// VMOptions=--force-switch-dispatch-type=0
// VMOptions=--force-switch-dispatch-type=1
// VMOptions=--force-switch-dispatch-type=2
import "package:expect/expect.dart";
String test(int n) {
String result = "foo";
switch (n) {
case 0:
result = "zero";
break;
case 1:
// fall-through, error if case is non-empty
case 9:
result = "nine";
// No implicit FallThroughError at end of switch statement.
}
return result;
}
main() {
Expect.equals("zero", test(0));
Expect.equals("nine", test(1));
Expect.equals("nine", test(9));
Expect.equals("foo", test(99));
}

View file

@ -1,7 +1,6 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Check that FallThroughError is thrown if switch clause does not terminate.
import "package:expect/expect.dart";
@ -16,10 +15,10 @@ String test(int n) {
// [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY
// [cfe] Switch case may fall through to the next case.
result = "one";
// fall-through, error if case is non-empty
// fall-through, error if case is non-empty
case 9:
result = "nine";
// No implicit FallThroughError at end of switch statement.
// No error at end of last switch case.
}
return result;
}

View file

@ -15,18 +15,12 @@ import "package:expect/expect.dart";
class EmptyBlockCaseTest {
static testMain() {
var exception = null;
try {
switch (1) {
case 1: /*@compile-error=unspecified*/
{}
case 2:
Expect.equals(true, false);
}
} on FallThroughError catch (e) {
exception = e;
switch (1) {
case 1: /*@compile-error=unspecified*/
{}
case 2:
Expect.equals(true, false);
}
Expect.equals(true, exception != null);
}
}

View file

@ -1,39 +0,0 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// @dart = 2.9
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Check that FallThroughError is thrown if switch clause does not terminate.
// VMOptions=
// VMOptions=--force-switch-dispatch-type=0
// VMOptions=--force-switch-dispatch-type=1
// VMOptions=--force-switch-dispatch-type=2
import "package:expect/expect.dart";
String test(int n) {
String result = "foo";
switch (n) {
case 0:
result = "zero";
break;
case 1:
// fall-through, error if case is non-empty
case 9:
result = "nine";
// No implicit FallThroughError at end of switch statement.
}
return result;
}
main() {
Expect.equals("zero", test(0));
Expect.equals("nine", test(1));
Expect.equals("nine", test(9));
Expect.equals("foo", test(99));
}

View file

@ -1,7 +1,6 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Check that FallThroughError is thrown if switch clause does not terminate.
// @dart = 2.9
@ -18,10 +17,10 @@ String test(int n) {
// [analyzer] COMPILE_TIME_ERROR.CASE_BLOCK_NOT_TERMINATED
// [cfe] Switch case may fall through to the next case.
result = "one";
// fall-through, error if case is non-empty
// fall-through, error if case is non-empty
case 9:
result = "nine";
// No implicit FallThroughError at end of switch statement.
// No error at end of last switch case.
}
return result;
}