Type untyped parameters with default expressions as union of any with the default...
commit689dd519aaa8ed2a83cebdb24552483f3e94b9f3
authorAndrew Kennedy <akenn@fb.com>
Tue, 9 Apr 2019 15:15:28 +0000 (9 08:15 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 9 Apr 2019 15:19:33 +0000 (9 08:19 -0700)
tree95161d472197c154377140a7dc4d0f7216e5d618
parent84f1ad6e52cd8f8e223e76ac15d2dced9b7dddcf
Type untyped parameters with default expressions as union of any with the default expression type

Summary:
In partial mode, an untyped parameter with a default expression is treated as having the type of the default expression. That's not quite right: values with other types can flow to the parameter, we should deal with this, but in a way that is consistent with the rules for partial mode.

One way to think about a default expression is as a conditional assignment. So
```
function foo($x = e) {
  ...
}
```
is equivalent (in terms of typing, not semantics!) to
```
function foo($x) {
  if (something) $x = e;
}
```
For untyped parameters, this means just taking the union of the type of `e` with `Tany`.

Note that for typed parameters, we check that the type of the default expression is a subtype of the declared type, so the union is redundant.

The issue was observed under new_inference, where
```
function foo($x = darray[]) {
}
```
ended up giving a very strict typing to `$x`, namely `darray<nothing,nothing>`.

Reviewed By: CatherineGasnier

Differential Revision: D14800828

fbshipit-source-id: 8ad410cb233b434336dc77e5ee0c2061a1b9e62a
hphp/hack/src/typing/typing.ml
hphp/hack/test/typecheck/default_empty.php [new file with mode: 0644]
hphp/hack/test/typecheck/default_empty.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/default_with_type_error.php [new file with mode: 0644]
hphp/hack/test/typecheck/default_with_type_error.php.exp [new file with mode: 0644]