2017-02-22 00:59:19 +03:00
|
|
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
exports[`test.js 1`] = `
|
|
|
|
====================================options=====================================
|
|
|
|
parsers: ["flow"]
|
|
|
|
printWidth: 80
|
|
|
|
| printWidth
|
|
|
|
=====================================input======================================
|
2017-04-12 23:41:51 +03:00
|
|
|
type CovArrayVerbose<X,Y:X> = Array<Y>;
|
2016-12-23 22:31:38 +03:00
|
|
|
var b: CovArrayVerbose<number,*> = [];
|
|
|
|
var y: CovArrayVerbose<mixed,*> = b;
|
2017-04-12 23:41:51 +03:00
|
|
|
y[0] = ""; // error
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
class NVerbose<E,I:E> {
|
|
|
|
x: CovArrayVerbose<E,I>;
|
|
|
|
foo(): CovArrayVerbose<mixed,I> { return this.x; }
|
|
|
|
}
|
|
|
|
|
|
|
|
var nv: NVerbose<number,*> = new NVerbose;
|
|
|
|
nv.x = [0];
|
|
|
|
(nv.x[0]: string); // error
|
|
|
|
(nv.foo()[0]: string); // error
|
|
|
|
|
|
|
|
/* TODO: use existentials for non-verbose covariance?
|
|
|
|
|
|
|
|
type CovArray<X> = Array<*:X>;
|
|
|
|
var c: CovArray<number> = [0];
|
|
|
|
var z: CovArray<string> = c; // error
|
|
|
|
|
|
|
|
var d: CovArray<number> = [];
|
|
|
|
var w: CovArray<mixed> = d;
|
2017-04-12 23:41:51 +03:00
|
|
|
w[0] = ""; // error
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
type P<X> = CovArray<X>;
|
|
|
|
var p: P<mixed> = [];
|
|
|
|
(p[0]: number); // not an error!
|
2017-04-12 23:41:51 +03:00
|
|
|
p[0] = ""; // error
|
2016-12-23 22:31:38 +03:00
|
|
|
|
|
|
|
class M {
|
|
|
|
x: CovArray<number>;
|
|
|
|
foo(): CovArray<mixed> { return this.x; }
|
|
|
|
bar(x: string) { this.foo()[0] = x; } // error
|
|
|
|
}
|
|
|
|
|
|
|
|
class N<E> {
|
|
|
|
x: CovArray<E>;
|
|
|
|
foo(): CovArray<mixed> { return this.x; }
|
|
|
|
bar(e: string) { this.foo()[0] = e; } // error
|
|
|
|
qux(e: E) { this.foo()[0] = e; }
|
|
|
|
}
|
|
|
|
|
|
|
|
var n: N<number> = new N;
|
|
|
|
n.x = [0];
|
|
|
|
(n.x[0]: string); // error
|
|
|
|
(n.foo()[0]: string); // not an error!
|
|
|
|
|
|
|
|
*/
|
2018-11-25 11:21:14 +03:00
|
|
|
|
|
|
|
=====================================output=====================================
|
2017-01-10 05:49:06 +03:00
|
|
|
type CovArrayVerbose<X, Y: X> = Array<Y>;
|
|
|
|
var b: CovArrayVerbose<number, *> = [];
|
|
|
|
var y: CovArrayVerbose<mixed, *> = b;
|
2017-04-12 23:41:51 +03:00
|
|
|
y[0] = ""; // error
|
2017-01-31 19:27:44 +03:00
|
|
|
|
2017-01-10 05:49:06 +03:00
|
|
|
class NVerbose<E, I: E> {
|
|
|
|
x: CovArrayVerbose<E, I>;
|
|
|
|
foo(): CovArrayVerbose<mixed, I> {
|
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 02:51:46 +03:00
|
|
|
var nv: NVerbose<number, *> = new NVerbose();
|
2017-01-24 22:38:12 +03:00
|
|
|
nv.x = [0];
|
2017-01-26 22:57:43 +03:00
|
|
|
(nv.x[0]: string); // error
|
2017-01-10 05:49:06 +03:00
|
|
|
(nv.foo()[0]: string); // error
|
2017-02-16 17:56:12 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
/* TODO: use existentials for non-verbose covariance?
|
|
|
|
|
|
|
|
type CovArray<X> = Array<*:X>;
|
|
|
|
var c: CovArray<number> = [0];
|
|
|
|
var z: CovArray<string> = c; // error
|
|
|
|
|
|
|
|
var d: CovArray<number> = [];
|
|
|
|
var w: CovArray<mixed> = d;
|
2017-04-12 23:41:51 +03:00
|
|
|
w[0] = ""; // error
|
2016-12-27 21:29:31 +03:00
|
|
|
|
|
|
|
type P<X> = CovArray<X>;
|
|
|
|
var p: P<mixed> = [];
|
|
|
|
(p[0]: number); // not an error!
|
2017-04-12 23:41:51 +03:00
|
|
|
p[0] = ""; // error
|
2016-12-27 21:29:31 +03:00
|
|
|
|
|
|
|
class M {
|
|
|
|
x: CovArray<number>;
|
|
|
|
foo(): CovArray<mixed> { return this.x; }
|
|
|
|
bar(x: string) { this.foo()[0] = x; } // error
|
|
|
|
}
|
|
|
|
|
|
|
|
class N<E> {
|
|
|
|
x: CovArray<E>;
|
|
|
|
foo(): CovArray<mixed> { return this.x; }
|
|
|
|
bar(e: string) { this.foo()[0] = e; } // error
|
|
|
|
qux(e: E) { this.foo()[0] = e; }
|
|
|
|
}
|
|
|
|
|
|
|
|
var n: N<number> = new N;
|
|
|
|
n.x = [0];
|
|
|
|
(n.x[0]: string); // error
|
|
|
|
(n.foo()[0]: string); // not an error!
|
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
*/
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2018-11-25 11:21:14 +03:00
|
|
|
================================================================================
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|