Created
January 6, 2017 19:04
-
-
Save acrylic-origami/368339195e2bb7dc449618468b31eeae to your computer and use it in GitHub Desktop.
A contravariant variation of #7585 that doesn't allow a violation.
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 | |
<<__ConsistentConstruct>> | |
abstract class ConWrapper<-T> { | |
public function __construct() {} | |
abstract public function act(T $v): void; | |
} | |
class ConcreteWrapper extends ConWrapper<OtherBase> { | |
public function act(OtherBase $v): void { | |
$v->fn(); | |
} | |
} | |
class Base {} | |
class OtherBase { | |
public function fn(): void {} | |
} | |
function violate(classname<ConWrapper<OtherBase>> $C): void { | |
(new $C())->act(new Base()); // Invalid argument (Typing[4110]) | |
} | |
// attempted violation: violate(ConcreteWrapper::class) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment