272 lines
6.8 KiB
Plaintext
272 lines
6.8 KiB
Plaintext
exports[`test array.js 1`] = `
|
|
"/* @flow */
|
|
|
|
var arrayTest1: Iterable<number> = ([1, 2]: Array<number>);
|
|
var arrayTest2: Iterable<number | string> = [1,2,\"hi\"];
|
|
var arrayTest3: Iterable<*> = [1,2,3];
|
|
|
|
// Error string ~> number
|
|
var arrayTest4: Iterable<number> = [\"hi\"];
|
|
// Error string ~> number
|
|
var arrayTest5: Iterable<string> = [\"hi\", 1];
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
var arrayTest1: Iterable<number> = ([ 1, 2 ]: Array<number>);
|
|
var arrayTest2: Iterable<number | string> = [ 1, 2, \"hi\" ];
|
|
var arrayTest3: Iterable<*> = [ 1, 2, 3 ];
|
|
|
|
// Error string ~> number
|
|
var arrayTest4: Iterable<number> = [ \"hi\" ];
|
|
// Error string ~> number
|
|
var arrayTest5: Iterable<string> = [ \"hi\", 1 ];
|
|
"
|
|
`;
|
|
|
|
exports[`test caching_bug.js 1`] = `
|
|
"/* @flow */
|
|
|
|
/**
|
|
* I\'ve hit a bug with the caching in flow_js.ml. Avik is removing that caching
|
|
* so it should be fixed soon. The basic idea is I flow something like
|
|
*
|
|
* Array<any | any> ~> Iterable<string>
|
|
*
|
|
* then Flow won\'t notice when I try to flow
|
|
*
|
|
* Array<string | number> ~> Iterable<string>
|
|
*
|
|
* We shouldn\'t hit the cache because the union types are different, but we do
|
|
* anyway. I\'ve fixed this temporarily by bumping the \"meaningful\" param to
|
|
* Hashtbl.hash_param
|
|
*/
|
|
|
|
function fill_the_cache(x: Array<any | any>): Iterable<string> { return x; }
|
|
|
|
// Error: number ~> string
|
|
function miss_the_cache(x: Array<string | number>): Iterable<string> { return x; }
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
/**
|
|
* I\'ve hit a bug with the caching in flow_js.ml. Avik is removing that caching
|
|
* so it should be fixed soon. The basic idea is I flow something like
|
|
*
|
|
* Array<any | any> ~> Iterable<string>
|
|
*
|
|
* then Flow won\'t notice when I try to flow
|
|
*
|
|
* Array<string | number> ~> Iterable<string>
|
|
*
|
|
* We shouldn\'t hit the cache because the union types are different, but we do
|
|
* anyway. I\'ve fixed this temporarily by bumping the \"meaningful\" param to
|
|
* Hashtbl.hash_param
|
|
*/
|
|
|
|
function fill_the_cache(x: Array<any | any>): Iterable<string> {
|
|
return x;
|
|
}
|
|
|
|
// Error: number ~> string
|
|
function miss_the_cache(x: Array<string | number>): Iterable<string> {
|
|
return x;
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test iter.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function foo(strs: Iterable<string>): void {
|
|
for (var s: string of strs) {
|
|
console.log(s);
|
|
}
|
|
}
|
|
|
|
var m: Map<string, number> = new Map();
|
|
|
|
foo(m.keys());
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function foo(strs: Iterable<string>): void {
|
|
for (var s: string of strs) {
|
|
console.log(s);
|
|
}
|
|
}
|
|
|
|
var m: Map<string, number> = new Map();
|
|
|
|
foo(m.keys());
|
|
"
|
|
`;
|
|
|
|
exports[`test iterator_result.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function makeIterator(coin_flip: () => boolean ): Iterator<string> {
|
|
return {
|
|
\"@@iterator\"() { return makeIterator(coin_flip); },
|
|
next(): IteratorResult<string, void> {
|
|
var done = coin_flip();
|
|
if (!done) {
|
|
return { done, value: \"still going...\" };
|
|
} else {
|
|
return { done };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function makeIterator(coin_flip: () => boolean ): Iterator<string> {
|
|
return {
|
|
\"@@iterator\"() { return makeIterator(coin_flip); },
|
|
next(): IteratorResult<string, void> {
|
|
var done = coin_flip();
|
|
if (done) { // Whoops, made a mistake and forgot to negate done
|
|
return { done, value: \"still going...\" }; // Error string ~> void
|
|
} else {
|
|
return { done }; // Error void ~> string
|
|
}
|
|
}
|
|
}
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function makeIterator(coin_flip: () => boolean): Iterator<string> {
|
|
return {
|
|
\"@@iterator\"() {
|
|
return makeIterator(coin_flip);
|
|
},
|
|
next(): IteratorResult<string, void> {
|
|
var done = coin_flip();
|
|
if (!done) {
|
|
return { done, value: \"still going...\" };
|
|
} else {
|
|
return { done };
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
function makeIterator(coin_flip: () => boolean): Iterator<string> {
|
|
return {
|
|
\"@@iterator\"() {
|
|
return makeIterator(coin_flip);
|
|
},
|
|
next(): IteratorResult<string, void> {
|
|
var done = coin_flip();
|
|
if (done) {
|
|
// Whoops, made a mistake and forgot to negate done
|
|
return { done, value: \"still going...\" }; // Error string ~> void
|
|
} else {
|
|
return { done }; // Error void ~> string
|
|
}
|
|
}
|
|
};
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test map.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function mapTest1(map: Map<string, number>): Iterable<[string, number]> {
|
|
return map;
|
|
}
|
|
function mapTest2<K, V>(map: Map<K, V>): Iterable<[K, V]> {
|
|
return map;
|
|
};
|
|
function mapTest3(map: Map<string, number>): Iterable<*> {
|
|
return map;
|
|
}
|
|
// Error - Map is an Iterable<[K, V]>
|
|
function mapTest4(map: Map<number, string>): Iterable<string> {
|
|
return map;
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function mapTest1(map: Map<string, number>): Iterable<[string, number]> {
|
|
return map;
|
|
}
|
|
function mapTest2<K, V>(map: Map<K, V>): Iterable<[K, V]> {
|
|
return map;
|
|
}
|
|
function mapTest3(map: Map<string, number>): Iterable<*> {
|
|
return map;
|
|
}
|
|
// Error - Map is an Iterable<[K, V]>
|
|
function mapTest4(map: Map<number, string>): Iterable<string> {
|
|
return map;
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test set.js 1`] = `
|
|
"/* @flow */
|
|
|
|
function setTest1(set: Set<string>): Iterable<string> {
|
|
return set;
|
|
}
|
|
function setTest2<T>(set: Set<T>): Iterable<T> {
|
|
return set;
|
|
};
|
|
function setTest3(set: Set<string>): Iterable<*> {
|
|
return set;
|
|
}
|
|
// Error string ~> number
|
|
function setTest4(set: Set<string>): Iterable<number> {
|
|
return set;
|
|
}
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
function setTest1(set: Set<string>): Iterable<string> {
|
|
return set;
|
|
}
|
|
function setTest2<T>(set: Set<T>): Iterable<T> {
|
|
return set;
|
|
}
|
|
function setTest3(set: Set<string>): Iterable<*> {
|
|
return set;
|
|
}
|
|
// Error string ~> number
|
|
function setTest4(set: Set<string>): Iterable<number> {
|
|
return set;
|
|
}
|
|
"
|
|
`;
|
|
|
|
exports[`test string.js 1`] = `
|
|
"/* @flow */
|
|
|
|
var stringTest1: Iterable<string> = \"hi\";
|
|
var stringTest3: Iterable<*> = \"hi\";
|
|
var stringTest3: Iterable<number> = \"hi\"; // Error - string is a Iterable<string>
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
var stringTest1: Iterable<string> = \"hi\";
|
|
var stringTest3: Iterable<*> = \"hi\";
|
|
var stringTest3: Iterable<number> = \"hi\"; // Error - string is a Iterable<string>
|
|
"
|
|
`;
|
|
|
|
exports[`test variance.js 1`] = `
|
|
"/* @flow */
|
|
|
|
(([]: Array<string>): Iterable<?string>); // ok, Iterable<+T>
|
|
|
|
(([]: Array<string>).values(): Iterable<?string>); // ok, Iterator<+T>
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
/* @flow */
|
|
|
|
(([]: Array<string>): Iterable<?string>);
|
|
|
|
// ok, Iterable<+T>
|
|
(([]: Array<string>).values(): Iterable<?string>); // ok, Iterator<+T>
|
|
"
|
|
`;
|