Last active
June 22, 2018 02:59
-
-
Save acrylic-origami/89857fff7980bff31cfbd131f37672a5 to your computer and use it in GitHub Desktop.
Why `this` in a contravariant position in an interface doesn't work out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh // strict | |
interface Base { | |
public function foo(this $v): void; | |
} | |
final class Derived<T> implements Base { | |
public function bar(): void {} | |
public function foo(this $v): void { | |
$v->bar(); // an `OtherDerived` here would be unwelcome. | |
} | |
} | |
final class OtherDerived implements Base { | |
public function foo(this $v): void {} | |
} | |
function violate(Base $v, Base $x): void { | |
$v->foo($x); | |
} | |
/* HH_FIXME[1002] Try to violate in strict mode */ | |
violate(new Derived(), new OtherDerived()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment