Stricter enforcement of arity for unpacked arguments
commit0e4d8c05c4dfc6bd3aee89a6c50e9220f9f7b0e7
authorKunal Mehta <kunalm@fb.com>
Thu, 8 Feb 2018 01:14:19 +0000 (7 17:14 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Thu, 8 Feb 2018 01:25:27 +0000 (7 17:25 -0800)
treeda120723c76ac22e08c9733fd04e835cb5b296f2
parentf918d01c726a441088b99055d428e8f1ddb442f3
Stricter enforcement of arity for unpacked arguments

Summary:
This diff adds a typechecker option to be stricter with argument unpacking. Consider the following function:

```
function max<T as num>(
  T $first,
  T $second,
  T ...$rest,
): T;
```

The typechecker currently allows us to call the function like this:

```
$max = max(...$my_numbers);
```

If that particular Container has no elements, this will be  a runtime exception. This diff requires that, when the option is set, that users pass in at least two arguments, and unpack the rest, or use a function that supports Containers:

```
$max = max($first, $second, ...$my_numbers);
// OR:
$max = max2($my_numbers);
```

Note that, in case of a tuple, we will allow the arguments to be unpacked because we can guarantee the arity:

```
$my_numbers = tuple(1, 2);
$max = max(...$my_numbers); // OK
```

Reviewed By: jamesjwu

Differential Revision: D6926957

fbshipit-source-id: 27942e0420d4e5d31c22493e72ea45689c6bd666
13 files changed:
hphp/hack/src/options/globalOptions.ml
hphp/hack/src/options/globalOptions.mli
hphp/hack/src/options/typecheckerOptions.ml
hphp/hack/src/typing/typing.ml
hphp/hack/test/typecheck/argument_unpacking/unpack_call1.php.exp
hphp/hack/test/typecheck/argument_unpacking/unpack_call11.php
hphp/hack/test/typecheck/argument_unpacking/unpack_call11.php.exp
hphp/hack/test/typecheck/argument_unpacking/unpack_call13_arity.php [new file with mode: 0644]
hphp/hack/test/typecheck/argument_unpacking/unpack_call13_arity.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/argument_unpacking/unpack_call13_arity.php.no_format [new file with mode: 0644]
hphp/hack/test/typecheck/argument_unpacking/unpack_call3.php.exp
hphp/hack/test/typecheck/argument_unpacking/unpack_call6.php.exp
hphp/hack/test/typecheck/construct/parent_construct1.php.exp