dart-sdk/tests/language/type/implicit_error_test.dart
Konstantin Shcheglov 7d3252800b Infer void return type for FunctionExpression.
https://github.com/dart-lang/language/pull/1092

Bug: https://github.com/dart-lang/sdk/issues/42720

Change-Id: I7ce44a066382c63e22debbcb652a717b5230b267
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154620
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-07-17 16:03:00 +00:00

46 lines
1.1 KiB
Dart

// Copyright (c) 2012, 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";
// Test that various type errors produced by implicit casts don't invoke
// user-defined code during error reporting.
class NoToString {
toString() {
Expect.fail("should not be called");
return "";
}
}
/// Defeat optimizations of type checks.
dynamic wrap(e) {
if (new DateTime.now().year == 1980) return null;
return e;
}
bool assertionsEnabled = false;
void main() {
assert(assertionsEnabled = true);
dynamic noToString = NoToString();
Expect.throws<TypeError>(() {
int x = wrap(noToString); // Implicit cast should throw
}, (e) {
e.toString(); // Should not throw.
return true;
});
if (assertionsEnabled) {
Expect.throws<TypeError>(() {
assert(wrap(noToString)); // Implicit cast should throw
}, (e) {
e.toString(); // Should not throw.
return true;
});
}
}