Files
test-repo/tests/flow/function/call.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

42 lines
1.1 KiB
JavaScript

// @flow
function test(a: string, b: number): number {
return this.length; // expect []/"" this
}
// args flow correctly into params
test.call("", "", 0);
// wrong this is an error
test.call(0, "", 0); // error: lookup `length` on Number
// not enough arguments is an error
test.call("", ""); // error: void ~> number
// mistyped arguments is an error
test.call("", "", ""); // error: string ~> number (2nd arg)
test.call("", 0, 0); // error: number ~> string (1st arg)
// resolve args array from tvar
function f(args) { test.call("", args[0], args[1]) }
f(["", 0]); // OK
f(["", ""]); // error: string ~> number (2nd arg)
f([0, 0]); // error: number ~> string (1st arg)
// expect 3 errors:
// - lookup length on Number (0 used as `this`)
// - number !~> string (param a)
// - string !~> number (param b)
(test.apply.call(test, 0, [0, 'foo']): number);
// args are optional
function test2(): number { return 0; }
(test2.call(): number);
(test2.call(""): number);
// callable objects
function test3(x: { (a: string, b: string): void }) {
x.call(x, 'foo', 'bar'); // ok
x.call(x, 'foo', 123); // error, number !~> string
}