Readonly closure calls
[hiphop-php.git] / hphp / hack / test / typecheck / readonly / call.php
bloba43f409804abef9bd1316242f2b561003995a89b
1 <?hh
2 <<file:__EnableUnstableFeatures('readonly')>>
3 class Foo {
4 public int $prop;
5 public (function(): void) $fprop;
6 public function __construct() {
7 $this->prop = 1;
8 $this->fprop = () ==> {};
10 public function set(int $y) : void {
11 $this->prop = $y;
14 public readonly function get() : int {
15 return 4;
20 function test(): void {
21 $x = readonly new Foo();
22 $y = $x->get(); // ok
23 $x->set(6); // error, can't call mutable function on readonly
26 // TODO: error against the $g typehint in nastcheck
27 function test_closure(readonly (readonly function() : void) $f, readonly (function(): void) $g) : void {
28 $f(); // ok
29 $g(); // error $g can't be called
30 $x = readonly new Foo();
31 ($x->fprop)();