Stop ignoring explicit ("as") cast failures on all but function types.

Change-Id: Ia421cce7bab4fe9c74775b5bf2474901475cfa89
Reviewed-on: https://dart-review.googlesource.com/53160
Reviewed-by: Vijay Menon <vsm@google.com>
This commit is contained in:
Bob Nystrom 2018-04-30 23:05:24 +00:00
parent d6a3b85ed2
commit 9d34963947
2 changed files with 16 additions and 5 deletions

View file

@ -10,6 +10,15 @@
### Dart VM
#### Dart Dev Compiler
* Failed `as` casts on `Iterable<T>`, `Map<T>`, `Future<T>`, and `Stream<T>`
are no longer ignored. These failures were ignored to make it easier to
migrate Dart 1 code to strong mode, but ignoring them is a hole in the type
system. This closes part of that hole. (We still need to stop ignoring
"as" cast failures on function types, and implicit cast failures on the above
types and function types.)
### Tool Changes
#### Pub

View file

@ -443,21 +443,23 @@ bool instanceOf(obj, type) {
}
@JSExportName('as')
cast(obj, type, bool typeError) {
cast(obj, type, bool isExplicit) {
if (obj == null) return obj;
var actual = getReifiedType(obj);
var result = isSubtype(actual, type);
if (JS(
'bool',
'# === true || # === null && dart.__ignoreWhitelistedErrors && #(#, #)',
'# === true || # === null && # && '
'dart.__ignoreWhitelistedErrors && #(#, #)',
result,
result,
isExplicit,
_ignoreTypeFailure,
actual,
type)) {
return obj;
}
return castError(obj, type, typeError);
return castError(obj, type, isExplicit);
}
bool test(bool obj) {
@ -484,7 +486,7 @@ void booleanConversionFailed(obj) {
"type '${typeName(expected)}' in boolean expression");
}
castError(obj, type, bool typeError) {
castError(obj, type, bool isExplicit) {
var objType = getReifiedType(obj);
if (JS('bool', '!dart.__ignoreAllErrors')) {
var errorInStrongMode = isSubtype(objType, type) == null;
@ -493,7 +495,7 @@ castError(obj, type, bool typeError) {
var expected = typeName(type);
if (JS('bool', 'dart.__trapRuntimeErrors')) JS('', 'debugger');
var error = JS('bool', '#', typeError)
var error = JS('bool', '#', isExplicit)
? new TypeErrorImplementation(obj, actual, expected, errorInStrongMode)
: new CastErrorImplementation(obj, actual, expected, errorInStrongMode);
throw error;