PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh // partial
  2. /* HH_FIXME[4336] */
  3. function my_compact<T>(Vector<?T> $vector): Vector<T> {
  4. }
  5. function test(bool $b): ?string {
  6. $nullable = Vector { null }; // Vector([?T]])
  7. $non_nullable = my_compact($nullable); // Vector([T])
  8. if ($b) {
  9. $res = $nullable;
  10. } else {
  11. $res = $non_nullable;
  12. }
  13. // integrating if branches unifies ?T with T, resulting in recursive type
  14. hh_show($res[0]); // Toption(Toption(Toption(Toption(Toption(...)))))
  15. return $res[0];
  16. }