New inference: fix double nullable issue
commitf16524f3a890410e01689e09f7f4925cf27e934d
authorAndrew Kennedy <akenn@fb.com>
Tue, 15 Jan 2019 17:10:56 +0000 (15 09:10 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 15 Jan 2019 17:16:01 +0000 (15 09:16 -0800)
tree306749c9c551ad9edc74a3b06180f3b6164139df
parent4f9a976f3de34d32ec604c56a2ffcb0561561c9b
New inference: fix double nullable issue

Summary:
It's possible to produce a "double nullable" that isn't refined by a null test. For example:
```
class Inv<T> {
public function __construct(T $_) {}
public function get(): ?T {
return null;
}
}

function expect_int(int $_): void {}

function test(?int $y): void {
  // new Inv<#1>($y) : Inv<#1>
  //   and ?int <: #1
  // After get, we have
  //   $y : ?#1
  // Refinement will just unwrap this nullable, leaving a type variable
  $y = (new Inv($y))->get();
  if ($y !== null) {
    expect_int($y);
  }
}
```
The easiest solution is to employ eager solving when expanding a type variable in the `non_null` helper function.

Reviewed By: CatherineGasnier

Differential Revision: D13669441

fbshipit-source-id: 1a2389cdfe89b1ca0111bf3b658de82cc13be59f
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_subtype.ml
hphp/hack/src/typing/typing_utils.ml
hphp/hack/test/typecheck/new_inference/eager_solve/double_nullable.php [new file with mode: 0644]
hphp/hack/test/typecheck/new_inference/eager_solve/double_nullable.php.exp [new file with mode: 0644]