Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c13676f

Browse files
lrhnCommit Queue
authored andcommitted
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 <[email protected]> Commit-Queue: Lasse Nielsen <[email protected]> Auto-Submit: Lasse Nielsen <[email protected]> Reviewed-by: Brian Quinlan <[email protected]>
1 parent f524ec7 commit c13676f

File tree

13 files changed

+28
-119
lines changed

13 files changed

+28
-119
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
[#34233]: https://github.com/dart-lang/sdk/issues/34233
7171
[`DEFAULT_BUFFER_SIZE`]: https://api.dart.dev/stable/2.17.6/dart-convert/JsonUtf8Encoder/DEFAULT_BUFFER_SIZE-constant.html
7272

73+
#### `dart:core`
74+
75+
- Deprecated `FallThroughError`. Has not been thrown since Dart 2.0.
76+
See [#24233][].
77+
7378
#### `dart:developer`
7479

7580
- **Breaking change** [#34233][]: The previously deprecated APIs

pkg/test_runner/lib/src/static_error.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class StaticError implements Comparable<StaticError> {
312312
return false;
313313
}
314314

315-
throw FallThroughError();
315+
throw UnsupportedError("ErrorSource ${source.name}");
316316
}
317317

318318
String toString() {

runtime/tests/concurrency/generate_stress_test_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Future<List<String>> findValidTests(List<String> directories, bool nnbd) async {
6868
'The following tests were filtered due to using blacklisted things:');
6969

7070
for (int i = 0; i < testFiles.length; ++i) {
71-
testFiles[i] = path.relative(testFiles[i], from: thisDir);
71+
testFiles[i] = path.relative(testFiles[i], from: thisDirectory);
7272
}
7373
if (File(tempFile).existsSync()) {
7474
File(tempFile).deleteSync();

runtime/tests/concurrency/stress_test_list.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,6 @@
25552555
"../../../tests/language/switch/case_expression_with_assignment_runtime_test.dart",
25562556
"../../../tests/language/switch/case_runtime_test.dart",
25572557
"../../../tests/language/switch/case_static_const_test.dart",
2558-
"../../../tests/language/switch/fallthru_runtime_test.dart",
25592558
"../../../tests/language/switch/infinite_switch_label_test.dart",
25602559
"../../../tests/language/switch/label2_test.dart",
25612560
"../../../tests/language/switch/label_test.dart",
@@ -5888,7 +5887,6 @@
58885887
"../../../tests/language_2/switch/case_expression_with_assignment_runtime_test.dart",
58895888
"../../../tests/language_2/switch/case_runtime_test.dart",
58905889
"../../../tests/language_2/switch/case_static_const_test.dart",
5891-
"../../../tests/language_2/switch/fallthru_runtime_test.dart",
58925890
"../../../tests/language_2/switch/infinite_switch_label_test.dart",
58935891
"../../../tests/language_2/switch/label2_test.dart",
58945892
"../../../tests/language_2/switch/label_test.dart",

runtime/vm/exceptions.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,11 +1143,6 @@ ObjectPtr Exceptions::Create(ExceptionType type, const Array& arguments) {
11431143
class_name = &Symbols::TypeError();
11441144
constructor_name = &Symbols::DotCreate();
11451145
break;
1146-
case kFallThrough:
1147-
library = Library::CoreLibrary();
1148-
class_name = &Symbols::FallThroughError();
1149-
constructor_name = &Symbols::DotCreate();
1150-
break;
11511146
case kAbstractClassInstantiation:
11521147
library = Library::CoreLibrary();
11531148
class_name = &Symbols::AbstractClassInstantiationError();

runtime/vm/exceptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class Exceptions : AllStatic {
6666
kAssertion,
6767
kCast,
6868
kType,
69-
kFallThrough,
7069
kAbstractClassInstantiation,
7170
kCyclicInitializationError,
7271
kCompileTimeError,

sdk/lib/core/errors.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,14 @@ class IndexError extends ArgumentError implements RangeError {
451451
}
452452
}
453453

454-
/// Error thrown when control reaches the end of a switch case.
454+
/// Error previously thrown when control reaches the end of a switch case.
455455
///
456-
/// The Dart specification requires this error to be thrown when
457-
/// control reaches the end of a switch case (except the last case
458-
/// of a switch) without meeting a break or similar end of the control
459-
/// flow.
456+
/// The pre-2.0 Dart specification required this error to be thrown when
457+
/// control reached the end of a switch case (except the last case
458+
/// of a switch) without meeting a `break` or other control flow operators.
459+
/// That kind of fall-through was made a compile-time error Dart 2.0,
460+
/// so this error no longer thrown.
461+
@Deprecated("No longer relevant in Dart 2.0")
460462
class FallThroughError extends Error {
461463
FallThroughError();
462464
@pragma("vm:entry-point")

tests/language/switch/empty_block_case_test.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ import "package:expect/expect.dart";
1414
class EmptyBlockCaseTest {
1515
static testMain() {
1616
var exception = null;
17-
try {
18-
switch (1) {
19-
case 1: /*@compile-error=unspecified*/
20-
{}
21-
case 2:
22-
Expect.equals(true, false);
23-
}
24-
} on FallThroughError catch (e) {
25-
exception = e;
17+
switch (1) {
18+
case 1: /*@compile-error=unspecified*/
19+
{}
20+
case 2:
21+
Expect.equals(true, false);
2622
}
27-
Expect.equals(true, exception != null);
2823
}
2924
}
3025

tests/language/switch/fallthru_runtime_test.dart

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/language/switch/fallthru_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4-
// Check that FallThroughError is thrown if switch clause does not terminate.
54

65
import "package:expect/expect.dart";
76

@@ -16,10 +15,10 @@ String test(int n) {
1615
// [analyzer] COMPILE_TIME_ERROR.SWITCH_CASE_COMPLETES_NORMALLY
1716
// [cfe] Switch case may fall through to the next case.
1817
result = "one";
19-
// fall-through, error if case is non-empty
18+
// fall-through, error if case is non-empty
2019
case 9:
2120
result = "nine";
22-
// No implicit FallThroughError at end of switch statement.
21+
// No error at end of last switch case.
2322
}
2423
return result;
2524
}

0 commit comments

Comments
 (0)