Organize the unit tests for global_write_check
[hiphop-php.git] / hphp / hack / test / typecheck / global_write_check / test_memoized.php
blobdba5280f47d3407d3b4a59b390d8d6cd7da46f5f
1 <?hh // strict
3 class Bar {
4 public int $prop = 0;
7 class Foo {
8 public static int $static_prop = 1;
9 <<__LateInit>> public static Bar $bar;
11 <<__Memoize>>
12 public static function foo_method_memoized(): int {
13 return self::$static_prop;
16 <<__MemoizeLSB>>
17 public static function foo_method_memoized_lsb(): Bar {
18 return self::$bar; // A global variable is passed to (or returned from) a function call.
22 <<__Memoize>>
23 function fun_memoized(): Bar {
24 return new Bar();
27 <<__Memoize>>
28 function fun_memoized_vec_int(): vec<int> {
29 return vec[1, 2, 3];
32 class Test {
33 public function test_method_call(): void {
34 (Foo::$bar)->prop = 1; // A global variable is written.
36 $a = Foo::foo_method_memoized();
37 $a = 2;
39 $b = Foo::foo_method_memoized_lsb();
40 $b->prop = 2; // A global variable is written.
42 $c = fun_memoized();
43 $c->prop = 2; // A global variable is written.
45 $d = fun_memoized_vec_int();
46 $d[0] = 2;