No error on use of `unsafe_cast`
[hiphop-php.git] / hphp / hack / test / typecheck / eq_constraint.php
blobdad83ac19d3f4f59b0f759b15c05839fd0a82813
1 <?hh // strict
3 class Foo {
4 public function assertIsFoo(): void {}
7 class Boxing<Tclass> {
8 public function __construct(
9 private Tclass $member,
10 ) {}
12 public function getWithDefault<Tinner>(
13 Tinner $default,
14 ): Tinner where
15 Tclass = ?Tinner,
17 return $this->member ?: $default;
20 public function getOrExcept<Tinner>(): Tinner where Tclass = ?Tinner {
21 if ($this->member === null) {
22 throw new Exception('Member is null and can\'t be got.');
24 return $this->member;
27 public function getAsIs(): Tclass {
28 return $this->member;
31 public static function caller(Boxing<?Foo> $c, Foo $f): void {
32 $c->getWithDefault($f)->assertIsFoo(); // Must succeed
33 $c->getOrExcept()->assertIsFoo(); // Must succeed
34 $c->getAsIs()->assertIsFoo(); // Must fail, because may be null