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
34 lines
901 B
JavaScript
34 lines
901 B
JavaScript
dart_library.library('functions', null, /* Imports */[
|
|
"dart_runtime/dart",
|
|
'dart/core'
|
|
], /* Lazy imports */[
|
|
], function(exports, dart, core) {
|
|
'use strict';
|
|
let dartx = dart.dartx;
|
|
function bootstrap() {
|
|
return dart.list([new Foo()], Foo);
|
|
}
|
|
dart.fn(bootstrap, () => dart.definiteFunctionType(core.List$(Foo), []));
|
|
let A2B$ = dart.generic(function(A, B) {
|
|
let A2B = dart.typedef('A2B', () => dart.functionType(B, [A]));
|
|
return A2B;
|
|
});
|
|
let A2B = A2B$();
|
|
function id(f) {
|
|
return f;
|
|
}
|
|
dart.fn(id, () => dart.definiteFunctionType(A2B$(Foo, Foo), [A2B$(Foo, Foo)]));
|
|
class Foo extends core.Object {}
|
|
function main() {
|
|
core.print(bootstrap()[dartx.get](0));
|
|
}
|
|
dart.fn(main, dart.void, []);
|
|
// Exports:
|
|
exports.bootstrap = bootstrap;
|
|
exports.A2B$ = A2B$;
|
|
exports.A2B = A2B;
|
|
exports.id = id;
|
|
exports.Foo = Foo;
|
|
exports.main = main;
|
|
});
|