facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.19k stars 3k forks source link

Reduce-like functions allow unsound type holes #9153

Closed muglug closed 2 years ago

muglug commented 2 years ago

Describe the bug

Type variables leaking from calls to reduce-like functions allows the following bug to go undiscovered:

function test(vec<int> $trav): void {
  $arr = HH\Lib\C\reduce($trav, ($acc_v, $element) ==> {
    $acc_v[] = $element;
    return $acc_v;
  }, vec[]);

  // $arr has type vec<int | [unresolved]>

  foreach ($arr as $a) {
    if (!$a is int) {
      // here $a has type [unresolved]
      $a->foo();
    }
  }
}

Expected behavior

$a can never not be an int, so the call should be flagged

Actual behavior

No errors!

Environment

muglug commented 2 years ago

Just realised this bug can never affect runtime execution, so closing.