2016-12-23 22:31:38 +03:00
|
|
|
exports[`test A.js 1`] = `
|
|
|
|
"class A {
|
|
|
|
foo(x:number):void { }
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = A;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
class A {
|
2017-01-16 19:31:32 +03:00
|
|
|
foo(x: number): void {
|
|
|
|
}
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
module.exports = A;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test B.js 1`] = `
|
2016-12-30 19:56:42 +03:00
|
|
|
"var A = require(\'./A\');
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
class B extends A { }
|
|
|
|
|
|
|
|
let b = new B();
|
|
|
|
(b.foo: number); // error, number !~> function
|
|
|
|
|
|
|
|
module.exports = B;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-30 19:56:42 +03:00
|
|
|
var A = require(\"./A\");
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
class B extends A {}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
let b = new B();
|
2016-12-27 21:29:31 +03:00
|
|
|
(b.foo: number);
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// error, number !~> function
|
2017-01-11 18:16:38 +03:00
|
|
|
module.exports = B;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test C.js 1`] = `
|
2016-12-30 19:56:42 +03:00
|
|
|
"var B = require(\'./B\');
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
class C extends B {
|
|
|
|
foo(x:string):void { }
|
|
|
|
}
|
|
|
|
|
|
|
|
let c = new C();
|
|
|
|
(c.foo: number); // error, number !~> function
|
|
|
|
|
|
|
|
module.exports = C;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-30 19:56:42 +03:00
|
|
|
var B = require(\"./B\");
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
class C extends B {
|
2017-01-16 19:31:32 +03:00
|
|
|
foo(x: string): void {
|
|
|
|
}
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
let c = new C();
|
2016-12-27 21:29:31 +03:00
|
|
|
(c.foo: number);
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// error, number !~> function
|
2017-01-11 18:16:38 +03:00
|
|
|
module.exports = C;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test D.js 1`] = `
|
|
|
|
"class D { }
|
|
|
|
class E { }
|
|
|
|
new E().x
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
class D {}
|
|
|
|
class E {}
|
2017-01-11 18:16:38 +03:00
|
|
|
new E().x;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
2017-01-23 01:33:04 +03:00
|
|
|
exports[`test binary.js 1`] = `
|
|
|
|
"(class {}) + 1;
|
|
|
|
(class a {}) + 1;
|
|
|
|
(class extends b {}) + 1;
|
|
|
|
(class a extends b {}) + 1;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
(class {}) + 1;
|
|
|
|
(class a {}) + 1;
|
|
|
|
(class extends b {}) + 1;
|
|
|
|
(class a extends b {}) + 1;
|
|
|
|
"
|
|
|
|
`;
|
|
|
|
|
2017-01-23 03:22:49 +03:00
|
|
|
exports[`test call.js 1`] = `
|
|
|
|
"(class {})(class {});
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
(class {})(class {});
|
|
|
|
"
|
|
|
|
`;
|
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
exports[`test class_shapes.js 1`] = `
|
|
|
|
"/* @flow */
|
|
|
|
|
|
|
|
type Foo = {
|
|
|
|
a: string; // exists in TestClass
|
2016-12-30 19:56:42 +03:00
|
|
|
b: string; // doesn\'t exist
|
2016-12-23 22:31:38 +03:00
|
|
|
c?: ?string; // exists in TestClass, optional
|
2016-12-30 19:56:42 +03:00
|
|
|
d?: number; // doesn\'t exist
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class TestClass {
|
|
|
|
a: string;
|
|
|
|
c: ?string;
|
|
|
|
}
|
|
|
|
|
|
|
|
var x = new TestClass();
|
|
|
|
|
|
|
|
x.a; // ok
|
|
|
|
x.b; // error, TestClass has no b
|
|
|
|
x.c; // ok
|
|
|
|
x.d; // error, TestClass has no d
|
|
|
|
|
|
|
|
var y : Foo = x;
|
2016-12-30 19:56:42 +03:00
|
|
|
y.b; // error, doesn\'t exist in TestClass
|
|
|
|
y.d; // ok, it\'s optional
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
class Test2Superclass {
|
|
|
|
a: number; // conflicts with cast to Foo
|
|
|
|
c: ?number; // conflicts with cast to Foo
|
|
|
|
}
|
|
|
|
class Test2Class extends Test2Superclass {
|
|
|
|
b: number; // conflicts with cast to Foo
|
|
|
|
}
|
|
|
|
|
|
|
|
var z = new Test2Class();
|
|
|
|
var w : Foo = z;
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
/* @flow */
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
type Foo = {
|
|
|
|
a: string,
|
|
|
|
// exists in TestClass
|
|
|
|
b: string,
|
|
|
|
// doesn\'t exist
|
|
|
|
c?: ?string,
|
|
|
|
// exists in TestClass, optional
|
|
|
|
d?: number /* doesn\'t exist*/
|
|
|
|
};
|
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
class TestClass {
|
|
|
|
a: string;
|
|
|
|
c: ?string;
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
var x = new TestClass();
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
x.a;
|
2017-01-10 05:49:06 +03:00
|
|
|
// ok
|
2016-12-27 21:29:31 +03:00
|
|
|
x.b;
|
2017-01-10 05:49:06 +03:00
|
|
|
// error, TestClass has no b
|
2016-12-27 21:29:31 +03:00
|
|
|
x.c;
|
2017-01-10 05:49:06 +03:00
|
|
|
// ok
|
2016-12-27 21:29:31 +03:00
|
|
|
x.d;
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// error, TestClass has no d
|
2016-12-23 22:31:38 +03:00
|
|
|
var y: Foo = x;
|
2016-12-27 21:29:31 +03:00
|
|
|
y.b;
|
2017-01-10 05:49:06 +03:00
|
|
|
// error, doesn\'t exist in TestClass
|
2016-12-27 21:29:31 +03:00
|
|
|
y.d;
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// ok, it\'s optional
|
2016-12-23 22:31:38 +03:00
|
|
|
class Test2Superclass {
|
2016-12-27 21:29:31 +03:00
|
|
|
a: number;
|
2017-01-10 05:49:06 +03:00
|
|
|
// conflicts with cast to Foo
|
|
|
|
c: ?number; // conflicts with cast to Foo
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
class Test2Class extends Test2Superclass {
|
2017-01-10 05:49:06 +03:00
|
|
|
b: number; // conflicts with cast to Foo
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
var z = new Test2Class();
|
2017-01-11 18:16:38 +03:00
|
|
|
var w: Foo = z;
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test expr.js 1`] = `
|
|
|
|
"var Bar = class Foo {
|
|
|
|
static factory(): Foo { // OK: Foo is a type in this scope
|
|
|
|
return new Foo() // OK: Foo is a runtime binding in this scope
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var bar1: Bar = new Bar() // OK
|
|
|
|
var bar2: Bar = Bar.factory() // OK
|
|
|
|
|
2016-12-30 19:56:42 +03:00
|
|
|
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
|
2016-12-23 22:31:38 +03:00
|
|
|
// unexpected failure in the above code.
|
|
|
|
|
|
|
|
var B = class Baz { }
|
|
|
|
var b = new Baz(); // error: Baz is not a runtime binding in this scope
|
|
|
|
|
|
|
|
var C = class Qux { }
|
|
|
|
var c: Qux = new C(); // error: Qux is not a type in this scope
|
|
|
|
|
|
|
|
// OK: anon classes create no binding, but can be bound manually
|
|
|
|
var Anon = class { }
|
|
|
|
var anon: Anon = new Anon();
|
|
|
|
|
|
|
|
class Alias { }
|
|
|
|
var _Alias = class Alias {
|
|
|
|
static factory(): Alias {
|
|
|
|
return new Alias();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var alias1: Alias = new _Alias(); // error: bad pun
|
|
|
|
var alias2: Alias = _Alias.factory(); // error: bad pun
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
var Bar = class Foo {
|
2016-12-27 21:29:31 +03:00
|
|
|
static factory(): Foo {
|
2017-01-10 05:49:06 +03:00
|
|
|
// OK: Foo is a type in this scope
|
2017-01-11 02:51:46 +03:00
|
|
|
return new Foo(); // OK: Foo is a runtime binding in this scope
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
};
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
var bar1: Bar = new Bar();
|
2017-01-10 05:49:06 +03:00
|
|
|
// OK
|
2016-12-27 21:29:31 +03:00
|
|
|
var bar2: Bar = Bar.factory();
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// OK
|
|
|
|
// NB: Don\'t write expected errors using Foo to avoid error collapse hiding an
|
|
|
|
// unexpected failure in the above code.
|
2016-12-23 22:31:38 +03:00
|
|
|
var B = class Baz {};
|
2017-01-11 02:51:46 +03:00
|
|
|
var b = new Baz();
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: Baz is not a runtime binding in this scope
|
2016-12-23 22:31:38 +03:00
|
|
|
var C = class Qux {};
|
2017-01-11 02:51:46 +03:00
|
|
|
var c: Qux = new C();
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: Qux is not a type in this scope
|
|
|
|
// OK: anon classes create no binding, but can be bound manually
|
2016-12-23 22:31:38 +03:00
|
|
|
var Anon = class {};
|
2017-01-11 02:51:46 +03:00
|
|
|
var anon: Anon = new Anon();
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
class Alias {}
|
|
|
|
var _Alias = class Alias {
|
2016-12-27 21:29:31 +03:00
|
|
|
static factory(): Alias {
|
2017-01-11 02:51:46 +03:00
|
|
|
return new Alias();
|
2016-12-23 22:31:38 +03:00
|
|
|
}
|
|
|
|
};
|
2017-01-11 02:51:46 +03:00
|
|
|
var alias1: Alias = new _Alias();
|
2017-01-10 05:49:06 +03:00
|
|
|
// error: bad pun
|
2017-01-11 18:16:38 +03:00
|
|
|
var alias2: Alias = _Alias.factory(); // error: bad pun
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test loc.js 1`] = `
|
|
|
|
"/* @flow */
|
|
|
|
|
|
|
|
type Foo = number
|
|
|
|
|
|
|
|
class Foo {} // error, shadows type Foo
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
/* @flow */
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
type Foo = number;
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
class Foo {} // error, shadows type Foo
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
exports[`test statics.js 1`] = `
|
|
|
|
"/* @flow */
|
|
|
|
|
|
|
|
class C {
|
|
|
|
static p: string;
|
|
|
|
}
|
2016-12-30 19:56:42 +03:00
|
|
|
C.p = \"hi\";
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
// Class static fields are compatible with object types
|
|
|
|
(C: {p:string}); // ok
|
|
|
|
(C: {p:number}); // errors, string ~> number & vice versa (unify)
|
|
|
|
|
|
|
|
declare var o: {p:number};
|
|
|
|
(o: Class<C>); // error, object type incompatible with class type
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-27 21:29:31 +03:00
|
|
|
/* @flow */
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
class C {
|
|
|
|
static p: string;
|
|
|
|
}
|
2016-12-30 19:56:42 +03:00
|
|
|
C.p = \"hi\";
|
2017-01-10 05:49:06 +03:00
|
|
|
|
|
|
|
// Class static fields are compatible with object types
|
2016-12-27 21:29:31 +03:00
|
|
|
(C: { p: string });
|
2017-01-10 05:49:06 +03:00
|
|
|
// ok
|
2016-12-27 21:29:31 +03:00
|
|
|
(C: { p: number });
|
2017-01-18 06:33:55 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
// errors, string ~> number & vice versa (unify)
|
2016-12-27 21:29:31 +03:00
|
|
|
declare var o: { p: number };
|
2017-01-11 18:16:38 +03:00
|
|
|
(o: Class<C>); // error, object type incompatible with class type
|
|
|
|
"
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|