/hphp/hack/test/typecheck/recursive_optional.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
- <?hh // partial
- /* HH_FIXME[4336] */
- function my_compact<T>(Vector<?T> $vector): Vector<T> {
- }
- function test(bool $b): ?string {
- $nullable = Vector { null }; // Vector([?T]])
- $non_nullable = my_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];
- }