From bea580c3a4588f28cefa9147e99da2dcab7b6d09 Mon Sep 17 00:00:00 2001 From: Vijay Menon Date: Mon, 21 May 2018 22:01:39 +0000 Subject: [PATCH] Disallow ignore on any explicit cast failures See #27223 Change-Id: I9689ce9a72597b3e5c945f9787f2de6c5e8c2074 Reviewed-on: https://dart-review.googlesource.com/54701 Commit-Queue: Vijay Menon Reviewed-by: Bob Nystrom Reviewed-by: Jenny Messerly --- pkg/dev_compiler/tool/ddb | 10 +++++++--- .../tool/input_sdk/private/ddc_runtime/errors.dart | 7 +++---- .../tool/input_sdk/private/ddc_runtime/operations.dart | 6 +++--- .../tool/input_sdk/private/ddc_runtime/runtime.dart | 1 + .../tool/input_sdk/private/ddc_runtime/types.dart | 8 +++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pkg/dev_compiler/tool/ddb b/pkg/dev_compiler/tool/ddb index 493b10311043..a9faea8075e1 100755 --- a/pkg/dev_compiler/tool/ddb +++ b/pkg/dev_compiler/tool/ddb @@ -18,6 +18,10 @@ import 'dart:io'; import 'package:args/args.dart' show ArgParser; import 'package:path/path.dart' as path; +// TODO(vsm): Remove this once we stop ignoring. It's off here, but +// configurable for manual testing. +const ignoreWhitelistedErrors = false; + void main(List args) { // Parse flags. var parser = new ArgParser() @@ -139,7 +143,7 @@ void main(List args) { function(sdk, app) { 'use strict'; sdk._debugger.registerDevtoolsFormatter(); - sdk.dart.ignoreWhitelistedErrors(false); + sdk.dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors); sdk._isolate_helper.startRootIsolate(() => {}, []); app.$basename.main(); }); @@ -162,7 +166,7 @@ void main(List args) { } let sdk = require(\"dart_sdk\"); let main = require(\"./$basename\").$basename.main; - sdk.dart.ignoreWhitelistedErrors(false); + sdk.dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors); try { sdk._isolate_helper.startRootIsolate(main, []); } catch(e) { @@ -186,7 +190,7 @@ void main(List args) { import { dart, _isolate_helper } from '$sdkJsPath/dart_sdk.js'; import { $basename } from '$basename.js'; let main = $basename.main; - dart.ignoreWhitelistedErrors(false); + dart.ignoreWhitelistedErrors($ignoreWhitelistedErrors); try { _isolate_helper.startRootIsolate(() => {}, []); main(); diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/errors.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/errors.dart index a6b3b0188292..b0b39e341a73 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/errors.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/errors.dart @@ -51,7 +51,7 @@ throwNullValueError() { null, new Symbol(''), null, null, null); } -castError(obj, expectedType, [bool typeError = undefined]) { +castError(obj, expectedType, [@js_helper.notNull bool isImplicit = false]) { var actualType = getReifiedType(obj); var message = _castErrorMessage(actualType, expectedType); if (JS('!', 'dart.__ignoreAllErrors')) { @@ -59,9 +59,8 @@ castError(obj, expectedType, [bool typeError = undefined]) { return obj; } if (JS('!', 'dart.__trapRuntimeErrors')) JS('', 'debugger'); - var error = JS('!', '#', typeError) - ? new TypeErrorImpl(message) - : new CastErrorImpl(message); + var error = + isImplicit ? new TypeErrorImpl(message) : new CastErrorImpl(message); throw error; } diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart index b8b88e2f173c..dd29a6c99ff6 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/operations.dart @@ -444,7 +444,7 @@ bool instanceOf(obj, type) { } @JSExportName('as') -cast(obj, type, bool isExplicit) { +cast(obj, type, @js_helper.notNull bool isImplicit) { if (obj == null) return obj; var actual = getReifiedType(obj); var result = isSubtype(actual, type); @@ -454,13 +454,13 @@ cast(obj, type, bool isExplicit) { 'dart.__ignoreWhitelistedErrors && #(#, #)', result, result, - isExplicit, + isImplicit, _ignoreTypeFailure, actual, type)) { return obj; } - return castError(obj, type, isExplicit); + return castError(obj, type, isImplicit); } bool test(bool obj) { diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart index fd62cd8735ce..15b43266690d 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/runtime.dart @@ -23,6 +23,7 @@ import 'dart:_js_helper' PrivateSymbol, ReifyFunctionTypes, NoReifyGeneric; +import 'dart:_js_helper' as js_helper show notNull; import 'dart:_debugger' show trackCall; export 'dart:_debugger' diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart index c7a40c5a0672..2d0df1bf5fdf 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart @@ -427,7 +427,7 @@ class FunctionType extends AbstractFunctionType { }))()'''); @JSExportName('as') - as_T(obj, [bool typeError]) { + as_T(obj, [@js_helper.notNull bool isImplicit = false]) { if (obj == null) return obj; if (JS('bool', 'typeof # == "function"', obj)) { var actual = JS('', '#[#]', obj, _runtimeType); @@ -436,12 +436,14 @@ class FunctionType extends AbstractFunctionType { if (actual == null) return obj; var result = isSubtype(actual, this); if (result == true) return obj; - if (result == null && JS('bool', 'dart.__ignoreWhitelistedErrors')) { + if (result == null && + isImplicit && + JS('!', 'dart.__ignoreWhitelistedErrors')) { _logIgnoredCast(actual, this); return obj; } } - return castError(obj, this, typeError); + return castError(obj, this, isImplicit); } @JSExportName('_check')