2 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5 function expect_int(int $_): void
{}
6 function expect_string(string $_): void
{}
7 function expect_num(num
$_): void
{}
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
{
27 // Enum Class user code
29 Box
<string> A
= new Box('bli');
30 IBox B
= Helper
::ibox();
31 Box
<int> B2
= new Box(42);
34 enum
class F
: ExBox
extends E
{
35 Box
<num
> C
= new Box(3.14);
39 abstract const type TEnum
as E
;
41 public function get
<T
>(HH\MemberOf
<this
::TEnum
, Box
<T
>> $param): T
{
45 public static function dictGen(): dict
<string, ExBox
> {
47 $ts = type_structure(static::class, 'TEnum');
48 $cls = $ts['classname'];
49 foreach ($cls::getValues() as $key => $elt) {
56 class Ext
extends Base
{
57 const type TEnum
= E
; // [0]
60 function test_constraint(): void
{
62 echo $ext->get(F
::C
); // F vs E, because of [0].