fix #28988, remove throw on Dart1 incompatible is-checks for dartdevc

We've had this flag off in testing for quite a while. This should not affect user code because it's removing a throw.

R=leafp@google.com

Review-Url: https://codereview.chromium.org/2996573002 .
This commit is contained in:
Jennifer Messerly 2017-08-07 16:41:12 -07:00
parent e606525894
commit 65e609548d
21 changed files with 126 additions and 406 deletions

View file

@ -73,6 +73,21 @@
* Support assert in const constructor initializer lists.
* Better formatting for multi-line strings in argument lists.
wasn't in a Git repository.
* Dart Dev Compiler
* dartdevc will no longer throw an error from `is` checks that return a
different result in weak mode
(SDK issue [28988](https://github.com/dart-lang/sdk/issues/28988)).
For example:
```dart
main() {
List l = [];
// Prints "false", does not throw.
print(l is List<String>);
}
```
## 1.24.2 - 22-06-2017

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -13,7 +13,6 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require',
let mochaOnError = window.onerror;
dart_sdk.dart.trapRuntimeErrors(false);
dart_sdk.dart.ignoreWhitelistedErrors(false);
dart_sdk.dart.failForWeakModeIsChecks(false);
dart_sdk._isolate_helper.startRootIsolate(function() {}, []);
// Make it easier to debug test failures and required for formatter test that
// assumes custom formatters are enabled.
@ -82,6 +81,7 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require',
'await_for_test': 'slow',
'bit_operations_test_none_multi': fail, // DDC/dart2js canonicalize bitop results to unsigned
'branch_canonicalization_test': fail, // JS bit operations truncate to 32 bits.
'call_test': fail,
'call_closurization_test': fail, // Functions do not expose a "call" method.
'call_test': fail,
'canonical_const2_test': fail,

View file

@ -143,16 +143,7 @@ define(['dart_sdk'], function(dart_sdk) {
suite('instanceOf', () => {
"use strict";
setup(() => {
dart_sdk.dart.failForWeakModeIsChecks(true);
});
teardown(() => {
dart_sdk.dart.failForWeakModeIsChecks(false);
});
let expect = assert.equal;
let isGroundType = dart.isGroundType;
let generic = dart.generic;
let intIsNonNullable = false;
let cast = dart.as;
@ -257,26 +248,15 @@ define(['dart_sdk'], function(dart_sdk) {
dart.fn((b, s, o) => { return null; },
dart.fnType(B, [B, String], {p: Object}));
function checkType(x, type, expectedTrue, strongOnly) {
function checkType(x, type, expectedTrue) {
if (expectedTrue === undefined) expectedTrue = true;
if (strongOnly === undefined) strongOnly = false;
if (!strongOnly) {
assert.doesNotThrow(() => instanceOf(x, type));
expect(instanceOf(x, type), expectedTrue,
'"' + x + '" ' +
(expectedTrue ? 'should' : 'should not') +
' be an instance of "' + dart.typeName(type) + '"');
} else {
assert.throws(() => instanceOf(x, type), dart.StrongModeError);
expect(expectedTrue, false);
expect(strongInstanceOf(x, type), null);
}
expect(instanceOf(x, type), expectedTrue,
'"' + x + '" ' +
(expectedTrue ? 'should' : 'should not') +
' be an instance of "' + dart.typeName(type) + '"');
}
test('int', () => {
expect(isGroundType(int), true);
expect(isGroundType(getReifiedType(5)), true);
checkType(5, int);
checkType(5, dynamic);
checkType(5, Object);
@ -294,7 +274,6 @@ define(['dart_sdk'], function(dart_sdk) {
});
test('dynamic', () => {
expect(isGroundType(dynamic), true);
checkType(new Object.new(), dynamic);
checkType(null, dynamic);
@ -302,7 +281,6 @@ define(['dart_sdk'], function(dart_sdk) {
});
test('Object', () => {
expect(isGroundType(Object), true);
checkType(new Object.new(), dynamic);
checkType(null, Object);
@ -321,8 +299,6 @@ define(['dart_sdk'], function(dart_sdk) {
});
test('String', () => {
expect(isGroundType(String), true);
expect(isGroundType(getReifiedType("foo")), true);
checkType("foo", String);
checkType("foo", Object);
checkType("foo", dynamic);
@ -355,19 +331,6 @@ define(['dart_sdk'], function(dart_sdk) {
let m5 = collection.LinkedHashMap.new();
let m6 = Map$(String, dart.dynamic).new();
expect(isGroundType(Map), true);
expect(isGroundType(getReifiedType(m1)), false);
expect(isGroundType(Map$(String, String)), false);
expect(isGroundType(getReifiedType(m2)), true);
expect(isGroundType(Map$(Object, Object)), true);
expect(isGroundType(getReifiedType(m3)), true);
expect(isGroundType(Map), true);
expect(isGroundType(getReifiedType(m4)), true);
expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true);
expect(isGroundType(getReifiedType(m5)), true);
expect(isGroundType(collection.LinkedHashMap), true);
expect(isGroundType(collection.LinkedHashMap), true);
// Map<T1,T2> <: Map
checkType(m1, Map);
checkType(m1, Object);
@ -392,10 +355,8 @@ define(['dart_sdk'], function(dart_sdk) {
checkType(m4, Map);
// Is checks
assert.throws(() => dart.is(m3, Map$(String, String)),
dart.StrongModeError);
assert.throws(() => dart.is(m6, Map$(String, String)),
dart.StrongModeError);
assert.isFalse(dart.is(m3, Map$(String, String)));
assert.isFalse(dart.is(m6, Map$(String, String)));
assert.isTrue(dart.is(m1, Map$(String, String)));
assert.isFalse(dart.is(m2, Map$(String, String)));
@ -448,12 +409,6 @@ define(['dart_sdk'], function(dart_sdk) {
let aabad = new (AA$(dart.dynamic, dart.dynamic).new)();
let aabadtype = getReifiedType(aabad);
expect(isGroundType(aatype), false);
expect(isGroundType(AA$(String, List)), false);
expect(isGroundType(bbtype), false);
expect(isGroundType(BB$(String, List)), false);
expect(isGroundType(cctype), true);
expect(isGroundType(CC), true);
checkType(cc, aatype, false);
checkType(cc, AA$(String, List), false);
checkType(cc, bbtype);
@ -466,8 +421,8 @@ define(['dart_sdk'], function(dart_sdk) {
checkType(bb, CC, false);
checkType(aa, aabadtype);
checkType(aa, dynamic);
checkType(aabad, aatype, false, true);
checkType(aabad, AA$(String, List), false, true);
checkType(aabad, aatype, false);
checkType(aabad, AA$(String, List), false);
checkType(aabad, aarawtype);
checkType(aabad, AA);
checkType(aaraw, aabadtype);
@ -516,17 +471,14 @@ define(['dart_sdk'], function(dart_sdk) {
test('Functions', () => {
// - return type: Dart is bivariant. We're covariant.
// - param types: Dart is bivariant. We're contravariant.
expect(isGroundType(Func2), true);
expect(isGroundType(Foo), false);
expect(isGroundType(fnTypeFuzzy(B, [B, String])), false);
checkType(bar1, Foo, false, true);
checkType(cls1, Foo, false, true);
checkType(bar1, fnTypeFuzzy(B, [B, String]), false, true);
checkType(cls1, fnTypeFuzzy(B, [B, String]), false, true);
checkType(bar2, Foo, false, true);
checkType(cls2, Foo, false, true);
checkType(bar2, fnTypeFuzzy(B, [B, String]), false, true);
checkType(cls2, fnTypeFuzzy(B, [B, String]), false, true);
checkType(bar1, Foo, false);
checkType(cls1, Foo, false);
checkType(bar1, fnTypeFuzzy(B, [B, String]), false);
checkType(cls1, fnTypeFuzzy(B, [B, String]), false);
checkType(bar2, Foo, false);
checkType(cls2, Foo, false);
checkType(bar2, fnTypeFuzzy(B, [B, String]), false);
checkType(cls2, fnTypeFuzzy(B, [B, String]), false);
checkType(bar3, Foo);
checkType(cls3, Foo);
checkType(bar3, fnTypeFuzzy(B, [B, String]));
@ -561,10 +513,8 @@ define(['dart_sdk'], function(dart_sdk) {
checkType(cls8, getReifiedType(bar7), false);
// Parameterized typedefs
expect(isGroundType(FuncG), true);
expect(isGroundType(FuncG$(B, String)), false);
checkType(bar1, FuncG$(B, String), false, true);
checkType(cls1, FuncG$(B, String), false, true);
checkType(bar1, FuncG$(B, String), false);
checkType(cls1, FuncG$(B, String), false);
checkType(bar3, FuncG$(B, String));
checkType(cls3, FuncG$(B, String));
});
@ -808,7 +758,7 @@ define(['dart_sdk'], function(dart_sdk) {
var obj = new O.new();
var m = dart.bind(obj, 'm');
checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true);
checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
// Test inherited signatures
class P extends O {
@ -819,7 +769,7 @@ define(['dart_sdk'], function(dart_sdk) {
var obj = new P.new();
var m = dart.bind(obj, 'm');
checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true);
checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
});
test('Object members', () => {

View file

@ -21,25 +21,6 @@ void ignoreAllErrors(bool flag) {
JS('', 'dart.__ignoreAllErrors = #', flag);
}
/// Throw an exception on `is` checks that would return an unsound answer in
/// non-strong mode Dart.
///
/// For example `x is List<int>` where `x = <Object>['hello']`.
///
/// These checks behave correctly in strong mode (they return false), however,
/// they will produce a different answer if run on a platform without strong
/// mode. As a debugging feature, these checks can be configured to throw, to
/// avoid seeing different behavior between modes.
///
/// (There are many other ways that different `is` behavior can be observed,
/// however, even with this flag. The most obvious is due to lack of reified
/// generic type parameters. This affects generic functions and methods, as
/// well as generic types when the type parameter was inferred. Setting this
/// flag to `true` will not catch these differences in behavior..)
void failForWeakModeIsChecks(bool flag) {
JS('', 'dart.__failForWeakModeIsChecks = #', flag);
}
throwCastError(object, actual, type) {
var found = typeName(actual);
var expected = typeName(type);

View file

@ -62,7 +62,7 @@ async_(gen, T, @rest args) => JS(
let result = FutureT.microtask(function() {
iter = $gen.apply(null, $args)[Symbol.iterator]();
var result = onValue();
if ($strongInstanceOf(result, FutureT) == null) {
if ($isSubtype($getReifiedType(result), FutureT) == null) {
// Chain the Future<dynamic> to a Future<T> to produce the correct
// final type.
return result.then($T)((x) => x, {onError: onError});

View file

@ -482,56 +482,44 @@ final _ignoreTypeFailure = JS('', '''(() => {
});
})()''');
/// Returns true if [obj] is an instance of [type]
/// Returns true if [obj] is a JS function and [type] is a function type
/// Returns false if [obj] is not an instance of [type] in both spec
/// and strong mode
/// Returns null if [obj] is not an instance of [type] in strong mode
/// but might be in spec mode
/// Returns true if [obj] is an instance of [type] in strong mode, otherwise
/// false.
///
/// This also allows arbitrary JS function objects to be subtypes of every Dart
/// function types.
bool strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => {
let actual = $getReifiedType($obj);
let result = $isSubtype(actual, $type);
if (result || (actual == $int && $isSubtype($double, $type))) return true;
if (actual == $jsobject && $_isFunctionType(type) &&
typeof(obj) === 'function') {
if (result ||
(actual == $int && $isSubtype($double, $type)) ||
(actual == $jsobject && $_isFunctionType(type) &&
typeof(obj) === 'function')) {
return true;
}
if (result === false) return false;
if (!dart.__ignoreWhitelistedErrors ||
($ignoreFromWhiteList == void 0)) {
return result;
if (result === null &&
dart.__ignoreWhitelistedErrors &&
$ignoreFromWhiteList &&
$_ignoreTypeFailure(actual, $type)) {
return true;
}
if ($_ignoreTypeFailure(actual, $type)) return true;
return result;
return false;
})()''');
/// Returns true if [obj] is null or an instance of [type]
/// Returns false if [obj] is non-null and not an instance of [type]
/// in strong mode
instanceOfOrNull(obj, type) => JS('', '''(() => {
bool instanceOfOrNull(obj, type) {
// If strongInstanceOf returns null, convert to false here.
if (($obj == null) || $strongInstanceOf($obj, $type, true)) return true;
return false;
})()''');
return obj == null || JS('bool', '#', strongInstanceOf(obj, type, true));
}
@JSExportName('is')
bool instanceOf(obj, type) => JS('', '''(() => {
if ($obj == null) {
return $type == $Null || $_isTop($type);
bool instanceOf(obj, type) {
if (obj == null) {
return JS('bool', '# == # || #', type, Null, _isTop(type));
}
let result = $strongInstanceOf($obj, $type);
if (result !== null) return result;
if (!dart.__failForWeakModeIsChecks) return false;
let actual = $getReifiedType($obj);
let message = 'Strong mode is-check failure: ' +
$typeName(actual) + ' does not soundly subtype ' +
$typeName($type);
if (!dart.__ignoreAllErrors) {
$throwStrongModeError(message);
}
console.error(message);
return true; // Match Dart 1.0 Semantics when ignoring errors.
})()''');
return strongInstanceOf(obj, type, false);
}
@JSExportName('as')
cast(obj, type) {

View file

@ -123,11 +123,8 @@ final global_ = JS(
settings.ignoreWhitelistedErrors : true);
$ignoreAllErrors(
'ignoreAllErrors' in settings ?settings.ignoreAllErrors : false);
'ignoreAllErrors' in settings ? settings.ignoreAllErrors : false);
$failForWeakModeIsChecks(
'failForWeakModeIsChecks' in settings ?
settings.failForWeakModeIsChecks : true);
$trackProfile(
'trackProfile' in settings ? settings.trackProfile : false);

View file

@ -1027,37 +1027,3 @@ isClassSubType(t1, t2, isCovariant) => JS(
// can return false.
return false;
})()''');
// TODO(jmesserly): this isn't currently used, but it could be if we want
// `obj is NonGroundType<T,S>` to be rejected at runtime instead of compile
// time.
isGroundType(type) => JS(
'',
'''(() => {
// TODO(vsm): Cache this if we start using it at runtime.
// TODO(jmesserly): implement for generic function types if we start using?
if ($type instanceof $Typedef) $type = $type.functionType;
if ($type instanceof $FunctionType) {
if (!$_isTop($type.returnType)) return false;
for (let i = 0; i < $type.args.length; ++i) {
if (!$_isBottom($type.args[i])) return false;
}
for (let i = 0; i < $type.optionals.length; ++i) {
if (!$_isBottom($type.optionals[i])) return false;
}
let names = $getOwnPropertyNames($type.named);
for (let i = 0; i < names.length; ++i) {
if (!$_isBottom($type.named[names[i]])) return false;
}
return true;
}
let typeArgs = $getGenericArgs($type);
if (!typeArgs) return true;
for (let t of typeArgs) {
if (t != $Object && t != $dynamic) return false;
}
return true;
})()''');

View file

@ -62,7 +62,6 @@ function finish(e) {
}
sdk.dart.ignoreWhitelistedErrors(false);
sdk.dart.failForWeakModeIsChecks(false);
sdk._isolate_helper.startRootIsolate(() => {}, []);
// Make it easier to debug test failures and required for formatter test that
// assumes custom formatters are enabled.

View file

@ -82,8 +82,6 @@ date_time10_test: RuntimeError # Issue 29921
growable_list_test: RuntimeError # Issue 29921
hash_set_test/01: RuntimeError # Issue 29921
iterable_to_list_test/*: RuntimeError
iterable_to_set_test: RuntimeError
list_unmodifiable_test: RuntimeError
list_test/none: RuntimeError
list_test/01: RuntimeError
nan_infinity_test/01: RuntimeError # Issue 29921

View file

@ -728,7 +728,6 @@ deferred_call_empty_before_load_test: RuntimeError # Issue 27777
deferred_load_library_wrong_args_test/01: MissingRuntimeError, RuntimeError # Issue 29920
deferred_not_loaded_check_test: RuntimeError # Issue 27777
deferred_redirecting_factory_test: RuntimeError # Issue 27777
deferred_regression_22995_test: RuntimeError # Issue 29920
deferred_static_seperate_test: RuntimeError # Issue 27777
double_int_to_string_test: RuntimeError # Issue 29920
dynamic_test: RuntimeError # Strong mode is-check failure: M1 does not soundly subtype Iface<dynamic, num>
@ -744,56 +743,21 @@ flatten_test/08: MissingRuntimeError # Issue 29920
flatten_test/09: MissingRuntimeError # Issue 29920
flatten_test/12: MissingRuntimeError # Issue 29920
for_variable_capture_test: RuntimeError # Issue 29920
function_subtype0_test: RuntimeError # Issue 29920
function_subtype1_test: RuntimeError # Issue 29920
function_subtype2_test: RuntimeError # Issue 29920
function_subtype3_test: RuntimeError # Issue 29920
function_subtype_bound_closure0_test: RuntimeError # Issue 29920
function_subtype_bound_closure1_test: RuntimeError # Issue 29920
function_subtype_bound_closure2_test: RuntimeError # Issue 29920
function_subtype_bound_closure3_test: RuntimeError # Issue 29920
function_subtype_bound_closure4_test: RuntimeError # Issue 29920
function_subtype_bound_closure5_test: RuntimeError # Issue 29920
function_subtype_bound_closure5a_test: RuntimeError # Issue 29920
function_subtype_bound_closure6_test: RuntimeError # Issue 29920
function_subtype_call0_test: RuntimeError # Issue 29920
function_subtype_call1_test: RuntimeError # Issue 29920
function_subtype_call2_test: RuntimeError # Issue 29920
function_subtype_cast0_test: RuntimeError # Issue 29920
function_subtype_cast1_test: RuntimeError # Issue 29920
function_subtype_cast2_test: RuntimeError # Issue 29920
function_subtype_cast3_test: RuntimeError # Issue 29920
function_subtype_factory0_test: RuntimeError # Issue 29920
function_subtype_inline0_test: RuntimeError # Issue 29920
function_subtype_local0_test: RuntimeError # Issue 29920
function_subtype_local1_test: RuntimeError # Issue 29920
function_subtype_local2_test: RuntimeError # Issue 29920
function_subtype_local3_test: RuntimeError # Issue 29920
function_subtype_local4_test: RuntimeError # Issue 29920
function_subtype_local5_test: RuntimeError # Issue 29920
function_subtype_named1_test: RuntimeError # Issue 29920
function_subtype_named2_test: RuntimeError # Issue 29920
function_subtype_not0_test: RuntimeError # Issue 29920
function_subtype_not1_test: RuntimeError # Issue 29920
function_subtype_not2_test: RuntimeError # Issue 29920
function_subtype_not3_test: RuntimeError # Issue 29920
function_subtype_optional1_test: RuntimeError # Issue 29920
function_subtype_optional2_test: RuntimeError # Issue 29920
function_subtype_top_level0_test: RuntimeError # Issue 29920
function_subtype_top_level1_test: RuntimeError # Issue 29920
function_subtype_typearg2_test: RuntimeError # Issue 29920
function_subtype_typearg4_test: RuntimeError # Issue 29920
function_type_alias2_test: RuntimeError # Issue 29920
function_type_alias3_test: RuntimeError # Issue 29920
function_type_alias4_test: RuntimeError # Issue 29920
generic_instanceof2_test: RuntimeError # Issue 29920
generic_instanceof_test: RuntimeError # Issue 29920
generic_is_check_test: RuntimeError # Issue 29920
generic_methods_generic_class_tearoff_test: RuntimeError # Issue 29920
generic_methods_named_parameters_test: RuntimeError # Issue 29920
generic_methods_optional_parameters_test: RuntimeError # Issue 29920
generic_methods_tearoff_specialization_test: RuntimeError # Issue 29920
generic_typedef_test: RuntimeError # Issue 29920
getter_closure_execution_order_test: RuntimeError # Issue 29920
identical_closure2_test: RuntimeError # Issue 29920
infinite_switch_label_test: RuntimeError # Issue 29920
@ -831,7 +795,6 @@ switch_try_catch_test: RuntimeError # Issue 29920
throwing_lazy_variable_test: RuntimeError # Issue 29920
truncdiv_test: RuntimeError # Issue 29920
type_variable_nested_test: RuntimeError # Issue 29920
type_variable_typedef_test: RuntimeError # Issue 29920
# This test does not generate the expected compile time error, but it also does
# not behave correctly at runtime. We cannot record this as "Fail" without

View file

@ -189,7 +189,6 @@ html/custom/regress_194523002_test: Crash # Issue 29922
[ $compiler == dartdevc && $runtime != none ]
async/future_or_bad_type_test/none: RuntimeError # Issue 29922
async/future_or_non_strong_test: RuntimeError # Issue 29922
async/future_or_strong_test: RuntimeError # Issue 29922
async/futures_test: RuntimeError # Issue 29922
async/slow_consumer_test: Pass, Timeout # Issue 29922
async/timer_not_available_test: RuntimeError # Issue 29922