a46de1c30c
Throwing `null` is not supported in sound null safety. This change inserts an implicit `as Object` cast that result in a TypeError, rather than a NullThrownError, in sound mode. Closes https://github.com/dart-lang/sdk/issues/49198 TEST=Covered by the existing tests Change-Id: I041baf95becd2df1b940fdff7cde398a4e391ee7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247546 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
43 lines
880 B
Dart
43 lines
880 B
Dart
// 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class ExceptionTest {
|
|
static testMain() {
|
|
int i = 0;
|
|
try {
|
|
throw "Hello";
|
|
} on String catch (s) {
|
|
print(s);
|
|
i += 10;
|
|
}
|
|
|
|
try {
|
|
throw "bye";
|
|
} on String catch (s) {
|
|
print(s);
|
|
i += 10;
|
|
}
|
|
Expect.equals(20, i);
|
|
|
|
bool correctCatch = false;
|
|
try {
|
|
// This throws TypeError
|
|
throw (null as dynamic);
|
|
} on String catch (s) {
|
|
correctCatch = false;
|
|
} on TypeError catch (e) {
|
|
correctCatch = true;
|
|
} catch (x) {
|
|
correctCatch = false;
|
|
}
|
|
Expect.isTrue(correctCatch);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
ExceptionTest.testMain();
|
|
}
|