Fix type checks and display for JS interop types.

Re-enable formatter test that had been disabled when someone changed type
name display for Foo<dynamic> types.
Fix bug in how type names were displayed for JS interop types.

BUG=
R=vsm@google.com

Review-Url: https://codereview.chromium.org/2789663005 .
This commit is contained in:
Jacob Richman 2017-04-03 08:34:13 -07:00
parent 3fd497b510
commit 509bcd58e1
15 changed files with 9001 additions and 8588 deletions

View file

@ -18,6 +18,7 @@ module.exports = function(config) {
{pattern: 'gen/codegen_output/language/**/*.js', included: false},
{pattern: 'gen/codegen_output/corelib/**/*.js', included: false},
{pattern: 'gen/codegen_output/lib/**/*.js', included: false},
{pattern: 'gen/codegen_tests/lib/**/*.txt', included: false},
{pattern: 'test/browser/*.js', included: false},
{pattern: 'node_modules/is_js/*.js', included: false},
'test-main.js',
@ -47,6 +48,11 @@ module.exports = function(config) {
// web server port
port: 9876,
// Proxy required to serve resources needed by tests.
proxies: {
'/root_dart/tests/lib/': '/base/gen/codegen_tests/lib/'
},
// enable / disable colors in the output (reporters and logs)
colors: true,

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

@ -417,9 +417,10 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require'],
'custom_elements_23127_test': async_unittest,
'custom_elements_test': async_unittest,
// TODO(jmesserly): investigate the change here; it is likely due to
// different reified types affecting the (gigantic) HTML literal
'debugger_test': fail, // firefox_fail
// Please do not mark this test as fail. If your change breaks this test,
// please look at the test for instructions on how to generate a new
// golden file.
'debugger_test': firefox_fail,
'element_animate_test': 'unittest',
// https://github.com/dart-lang/sdk/issues/27579.

View file

@ -66,7 +66,7 @@ class Dynamic extends TypeRep {
toString() => 'dynamic';
}
class LazyJSType implements Type {
class LazyJSType extends TypeRep {
final _jsTypeCallback;
final _dartName;
@ -114,7 +114,10 @@ _asInstanceOfLazyJSType(o, LazyJSType t) {
return o;
}
bool _isJSObject(o) => JS('bool', '!dart.getReifiedType(o)[dart._runtimeType]');
bool _isJSObject(o) =>
JS('bool', '!dart.getReifiedType(#)[dart._runtimeType]', o);
bool _isJSType(t) => JS('bool', '!#[dart._runtimeType]', t);
@JSExportName('dynamic')
final _dynamic = new Dynamic();
@ -577,12 +580,12 @@ getImplicitFunctionType(type) {
bool isFunctionType(type) => JS('bool', '# instanceof # || # === #', type,
AbstractFunctionType, type, Function);
isLazyJSSubtype(LazyJSType t1, LazyJSType t2, isCovariant) {
if (t1 == t2) return true;
// All anonymous JS types are subtypes of each other.
if (t1._jsTypeCallback == null || t2._jsTypeCallback == null) return true;
return isClassSubType(t1._rawJSType, t2._rawJSType, isCovariant);
isLazyJSSubtype(t1, LazyJSType t2, isCovariant) {
// All JS types are subtypes of anonymous JS types.
if (t2._jsTypeCallback == null) {
return _isJSType(t1);
}
return _isSubtype(t1, t2._rawJSType, isCovariant);
}
/// Returns true if [ft1] <: [ft2].
@ -765,6 +768,10 @@ _isSubtype(t1, t2, isCovariant) => JS(
if (result === true || result === null) return result;
}
if ($t2 instanceof $LazyJSType) {
return $isLazyJSSubtype($t1, $t2, $isCovariant);
}
// Function subtyping.
// Handle Objects with call methods. Those are functions
@ -775,11 +782,7 @@ _isSubtype(t1, t2, isCovariant) => JS(
if ($isFunctionType($t1) && $isFunctionType($t2)) {
return $isFunctionSubtype($t1, $t2, $isCovariant);
}
if ($t1 instanceof $LazyJSType && $t2 instanceof $LazyJSType) {
return $isLazyJSSubtype($t1, $t2, $isCovariant);
}
return false;
})()''');

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -46,6 +46,12 @@ class FooImpl extends Foo<LazyClass> {
LazyClass get obj => new LazyClass(100);
}
class ExampleGenericClass<T> {
String add(T foo) {
return foo.toString();
}
}
main() {
group('lazy property', () {
test('simple', () {
@ -109,6 +115,29 @@ baz.LazyClass = function LazyClass(a) {
expect(<AnonClass>[] is! List<LazyClass>, isTrue);
expect(<int>[] is! List<LazyClass>, isTrue);
expect(<LazyClass>[] is List<LazyClass>, isTrue);
var listLazyClass = <LazyClass>[];
Object instanceLazyObject = l;
expect(() => listLazyClass.add(42 as dynamic), throws);
// Regression test for bug where this call failed.
listLazyClass.add(instanceLazyObject);
listLazyClass.add(null);
dynamic listLazyClassDynamic = listLazyClass;
expect(() => listLazyClassDynamic.add(42), throws);
// Regression test for bug where this call failed.
listLazyClassDynamic.add(instanceLazyObject);
listLazyClassDynamic.add(null);
var genericClass = new ExampleGenericClass<LazyClass>();
genericClass.add(instanceLazyObject);
expect(() => genericClass.add(42 as dynamic), throws);
genericClass.add(null);
dynamic genericClassDynamic = genericClass;
genericClassDynamic.add(instanceLazyObject);
expect(() => genericClassDynamic.add(42), throws);
genericClassDynamic.add(null);
});
});
}