Files
test-repo/tests/flow/function/rest.js
T
Simon Lydell dc93bdc983 Sync the Flow tests (#1163)
* Extract custom tests from tests/flow/

Approach:

1. Remove all .js files in tests/flow except .snap.js files.
2. Copy over all .js files from tests/ in the flow repo.
3. Go through the diff looking for deletions.
   - It was easy to see which deletions were due to changes in the tests
     due to updates in the flow repo.
   - For the rest of the deletions, I used `git blame` to verify that
     they had been added by us since the flow tests were copied over.

This makes tests/flow/ simply a copy of the tests from the flow repo,
making it easier to sync with the upstream flow tests in the future.

* Add a script for syncing the flow tests

* Sync the flow tests
2017-04-08 07:52:38 -07:00

62 lines
1.8 KiB
JavaScript

/* regression tests */
function rest_array<T>(...xs: Array<T>): T { // Ok, arrays can be rest params
return xs[0];
}
function rest_tuple<T>(...xs: [T]): T { // Ok, tuples can be rest params
return xs[0];
}
function rest_ro_array<T>(...xs: $ReadOnlyArray<T>): T { // Ok
return xs[0];
}
function rest_any(...xs: any): any { // Ok, any can be a rest param
return xs[0];
}
function rest_t<U, T: Array<U>>(...xs: T): U { // Ok, bounded targ can be rest
return xs[0];
}
// These are ok bounds for the rest param
function unbound_rest_t<T>(...xs: T): void {}
function mixed_rest_t<T: mixed>(...xs: T): void {}
function array_rest_t<T: Array<mixed>>(...xs: T): void {}
function roarray_rest_t<T: $ReadOnlyArray<mixed>>(...xs: T): void {}
function iterable_rest_t<T: Iterable<mixed>>(...xs: T): void {}
function empty_rest_t<T: empty>(...xs: T): void {}
function bounds_on_bounds<T>() {
return function<U: T>(...xs: T): void {}
}
// These are bad bounds for the rest param
function bad_unbound_rest_t<T>(...xs: T): T {
return xs.pop(); // Error - no bound on T
}
function string_rest_t<T: string>(...xs: T): void {} // Error - rest param can't be a string
function empty_rest_t<T: empty>(...xs: T): void {} // Error - rest param can't be empty
type Rest = Array<string>;
function rest_alias(...xs: Rest): void {} // Ok
function rest_union(...xs: [1,2] | Array<number>): number { // OK
return xs[0];
}
function rest_intersection(...xs: { x: number } & [1,2]): number { // OK
return xs[0] + xs.x;
}
function empty_rest<T:Array<mixed>>(...xs: T): T { return xs; }
(empty_rest(): empty); // Error Array ~> empty
function return_rest_param<Args:Array<mixed>>(
f: (...args: Args) => void,
): (...args: Args) => number {
return function(...args) {
return args; // Error: Array ~> number
}
}