Fix bug with enforcing purity in constant initializers
[hiphop-php.git] / hphp / hack / test / enum_class / typing / typing3.bad.php
blob3671763a4340fba762a2d8dbf4ee8728de39ce2d
1 <?hh
2 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 // User code
5 function expect_int(int $_): void {}
6 function expect_string(string $_): void {}
7 function expect_num(num $_): void {}
9 interface ExBox {}
11 class Box<T> implements ExBox {
12 public function __construct(public T $data)[] {}
15 class IBox extends Box<int> {
16 public function add(int $x)[write_props]: void {
17 $this->data = $this->data + $x;
21 abstract final class Helper {
22 public static function ibox()[]: IBox {
23 return new IBox(42);
27 // Enum Class user code
28 enum class E: ExBox {
29 Box<string> A = new Box('bli');
30 IBox B = Helper::ibox();
31 Box<int> B2 = new Box(42);
34 function generic2<TEnum as E, TBox as IBox>(
35 HH\MemberOf<TEnum, TBox> $param
36 ): int {
37 $param->add(42);
38 return $param->data;
41 function testit2(): void {
42 expect_int(generic2(E::B2)); // errors as it should