4e7920c487
This changes the way we handle dynamic at runtime to be more correct and cleaner. We now simply emit dynamic as dynamic instead of as core.Object. There are now two ways to construct a function type: one can construct a fuzzy function type (the default), or a definite function type. The constructor for a fuzzy function type replaces all uses of dynamic with bottom. This function type is used for all type annotations. Definite function types do not replace dynamic with bottom. These only occur as the runtime type of actual functions, for which we really know the type. Because we now eagerly sort this out when we create the function type, the subtyping code doesn't need to deal with this. This allows some additional subtyping: closures which actually are typed to take dynamic would previously not have been allowed to be cast to something with a concrete argument type. Now this is allowed (see the change in runtime_tests.js for an example of this). This fixes #107. BUG= R=vsm@google.com Review URL: https://codereview.chromium.org/1195523002
86 lines
1.7 KiB
JavaScript
86 lines
1.7 KiB
JavaScript
dart_library.library('methods', null, /* Imports */[
|
|
"dart_runtime/dart",
|
|
'dart/core'
|
|
], /* Lazy imports */[
|
|
], function(exports, dart, core) {
|
|
'use strict';
|
|
let dartx = dart.dartx;
|
|
let _c = Symbol('_c');
|
|
class A extends core.Object {
|
|
A() {
|
|
this[_c] = 3;
|
|
}
|
|
x() {
|
|
return 42;
|
|
}
|
|
y(a) {
|
|
return a;
|
|
}
|
|
z(b) {
|
|
if (b === void 0)
|
|
b = null;
|
|
return b;
|
|
}
|
|
zz(b) {
|
|
if (b === void 0)
|
|
b = 0;
|
|
return b;
|
|
}
|
|
w(a, opts) {
|
|
let b = opts && 'b' in opts ? opts.b : null;
|
|
return dart.notNull(a) + dart.notNull(b);
|
|
}
|
|
ww(a, opts) {
|
|
let b = opts && 'b' in opts ? opts.b : 0;
|
|
return dart.notNull(a) + dart.notNull(b);
|
|
}
|
|
get a() {
|
|
return this.x();
|
|
}
|
|
set b(b) {}
|
|
get c() {
|
|
return this[_c];
|
|
}
|
|
set c(c) {
|
|
this[_c] = c;
|
|
}
|
|
}
|
|
dart.setSignature(A, {
|
|
methods: () => ({
|
|
x: [core.int, []],
|
|
y: [core.int, [core.int]],
|
|
z: [core.int, [], [core.num]],
|
|
zz: [core.int, [], [core.int]],
|
|
w: [core.int, [core.int], {b: core.num}],
|
|
ww: [core.int, [core.int], {b: core.int}]
|
|
})
|
|
});
|
|
class Bar extends core.Object {
|
|
call(x) {
|
|
return core.print(`hello from ${x}`);
|
|
}
|
|
}
|
|
dart.setSignature(Bar, {
|
|
methods: () => ({call: [dart.dynamic, [dart.dynamic]]})
|
|
});
|
|
class Foo extends core.Object {
|
|
Foo() {
|
|
this.bar = new Bar();
|
|
}
|
|
}
|
|
function test() {
|
|
let f = new Foo();
|
|
dart.dcall(f.bar, "Bar's call method!");
|
|
let a = new A();
|
|
let g = dart.bind(a, 'x');
|
|
let aa = new A();
|
|
let h = dart.dload(aa, 'x');
|
|
}
|
|
dart.fn(test);
|
|
// Exports:
|
|
exports.A = A;
|
|
exports.Bar = Bar;
|
|
exports.Foo = Foo;
|
|
exports.test = test;
|
|
});
|