Untyped variadic function types should not be permitted in strict mode
commit3a44e3dcab6a298b2d304bda242137bde1ae17d0
authorArun Kumar <arkumar@fb.com>
Mon, 12 Feb 2018 12:09:15 +0000 (12 04:09 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Mon, 12 Feb 2018 12:14:53 +0000 (12 04:14 -0800)
tree432e1e02ac52fed9d023887ca53aed43cf77d10e
parent54a996c36d2d2f9a8444dd592593dac04796c354
Untyped variadic function types should not be permitted in strict mode

Summary:
Hack allows for two different syntaxes for variadics:

The Hack syntax with `...`:
```
function foo(int $a, ...):void { $args = func_get_args(); }
```
and the PHP version with ```...$param_name```:
```
function foo(int $a, ...$args):void { $x = $args[0]; }
```

In strict mode, the typechecker forbids:

```
function foo(...$x):int{  // type hint required on ...$x
  return 5;
}
```

while allowing

```
function foo(...):int{
  return 5;
}
```

This diff changes the typechecker behaviour and disallows the `...` syntax in strict mode. Consequently, only variadics with a parameter name and type hint will be allowed in strict mode.

Reviewed By: andrewjkennedy

Differential Revision: D6834122

fbshipit-source-id: 21ed2341956bc295f07e08f03f25e952c3d55d31
26 files changed:
hphp/hack/src/typing/typing.ml
hphp/hack/src/utils/errors/errors.ml
hphp/hack/src/utils/errors/errors_sig.ml
hphp/hack/test/typecheck/ellipsis_as_function_param_non_strict.php [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_as_function_param_non_strict.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_as_function_param_strict.php [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_as_function_param_strict.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_in_function_hint_non_strict.php [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_in_function_hint_non_strict.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_in_function_hint_strict.php [new file with mode: 0644]
hphp/hack/test/typecheck/ellipsis_in_function_hint_strict.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/functional_dots.php
hphp/hack/test/typecheck/functional_dots.php.exp
hphp/hack/test/typecheck/functional_dots2.php
hphp/hack/test/typecheck/functional_dots3.php
hphp/hack/test/typecheck/functional_dots4.php
hphp/hack/test/typecheck/functional_dots5.php
hphp/hack/test/typecheck/lambda/lambda_contextual/lambda_ambiguous.php.exp
hphp/hack/test/typecheck/prettyprint/variadic_functions.php
hphp/hack/test/typecheck/prettyprint/variadic_functions.php.exp
hphp/hack/test/typecheck/printf.php
hphp/hack/test/typecheck/printf2.php
hphp/hack/test/typecheck/printf3.php
hphp/hack/test/typecheck/printf4.php
hphp/hack/test/typecheck/printf5.php
hphp/hack/test/typecheck/var_args.php