hiphop-php /hphp/hack/test/typecheck/recursive_optional.php

Language PHP Lines 21
MD5 Hash 9e2c4ecf59e4b7573b68dfb0a9522256 Estimated Cost $306 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?hh

function compact<T>(Vector<?T> $vector): Vector<T> {
  //UNSAFE
}

function test(bool $b): ?string {

  $nullable = Vector {null}; // Vector([?T]])
  $non_nullable = compact($nullable); // Vector([T])

  if ($b) {
    $res = $nullable;
  } else {
    $res = $non_nullable;
  }
  // integrating if branches unifies ?T with T, resulting in recursive type
  hh_show($res[0]); // Toption(Toption(Toption(Toption(Toption(...)))))
  return $res[0];
}
Back to Top