PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 20 lines | 14 code | 4 blank | 2 comment | 2 complexity | 3a5e68c964596f3327c79ba8e582668d MD5 | raw file
 1<?hh // partial
 2
 3/* HH_FIXME[4336] */
 4function my_compact<T>(Vector<?T> $vector): Vector<T> {
 5}
 6
 7function test(bool $b): ?string {
 8
 9  $nullable = Vector { null }; // Vector([?T]])
10  $non_nullable = my_compact($nullable); // Vector([T])
11
12  if ($b) {
13    $res = $nullable;
14  } else {
15    $res = $non_nullable;
16  }
17  // integrating if branches unifies ?T with T, resulting in recursive type
18  hh_show($res[0]); // Toption(Toption(Toption(Toption(Toption(...)))))
19  return $res[0];
20}