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
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
dart_library.library('misc', null, /* Imports */[
|
|
"dart_runtime/dart",
|
|
'dart/core'
|
|
], /* Lazy imports */[
|
|
], function(exports, dart, core) {
|
|
'use strict';
|
|
let dartx = dart.dartx;
|
|
class _Uninitialized extends core.Object {
|
|
_Uninitialized() {
|
|
}
|
|
}
|
|
dart.setSignature(_Uninitialized, {
|
|
constructors: () => ({_Uninitialized: [_Uninitialized, []]})
|
|
});
|
|
let UNINITIALIZED = dart.const(new _Uninitialized());
|
|
let Generic$ = dart.generic(function(T) {
|
|
class Generic extends core.Object {
|
|
get type() {
|
|
return Generic$();
|
|
}
|
|
}
|
|
return Generic;
|
|
});
|
|
let Generic = Generic$();
|
|
class Base extends core.Object {
|
|
Base() {
|
|
this.x = 1;
|
|
this.y = 2;
|
|
}
|
|
['=='](obj) {
|
|
return dart.is(obj, Base) && dart.equals(dart.dload(obj, 'x'), this.x) && dart.equals(dart.dload(obj, 'y'), this.y);
|
|
}
|
|
}
|
|
class Derived extends core.Object {
|
|
Derived() {
|
|
this.z = 3;
|
|
}
|
|
['=='](obj) {
|
|
return dart.is(obj, Derived) && dart.equals(dart.dload(obj, 'z'), this.z) && super['=='](obj);
|
|
}
|
|
}
|
|
function _isWhitespace(ch) {
|
|
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
|
|
}
|
|
dart.fn(_isWhitespace, core.bool, [core.String]);
|
|
let _escapeMap = dart.const(dart.map({'\n': '\\n', '\r': '\\r', '\f': '\\f', '\b': '\\b', '\t': '\\t', '\v': '\\v', '': '\\x7F'}));
|
|
function main() {
|
|
core.print(dart.toString(1));
|
|
core.print(dart.toString(1.0));
|
|
core.print(dart.toString(1.1));
|
|
let x = 42;
|
|
core.print(dart.equals(x, dart.dynamic));
|
|
core.print(dart.equals(x, Generic));
|
|
core.print(new (Generic$(core.int))().type);
|
|
core.print(dart.equals(new Derived(), new Derived()));
|
|
}
|
|
dart.fn(main);
|
|
// Exports:
|
|
exports.UNINITIALIZED = UNINITIALIZED;
|
|
exports.Generic$ = Generic$;
|
|
exports.Generic = Generic;
|
|
exports.Base = Base;
|
|
exports.Derived = Derived;
|
|
exports.main = main;
|
|
});
|