Skip to content

Commit 14a8b06

Browse files
Add test
1 parent 8832cc5 commit 14a8b06

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug13782;
4+
5+
use BackedEnum;
6+
use function PHPStan\Testing\assertType;
7+
8+
enum IntEnum : int
9+
{
10+
case A = 1;
11+
case B = 2;
12+
}
13+
14+
class EnumMethods
15+
{
16+
/**
17+
* @template TEnum of BackedEnum
18+
* @param TEnum $enum
19+
* @return value-of<TEnum>
20+
*/
21+
public static function getValue(BackedEnum $enum): int|string
22+
{
23+
return $enum->value;
24+
}
25+
26+
/**
27+
* @template TEnum of BackedEnum
28+
* @param TEnum|null $enum
29+
* @return ($enum is TEnum ? value-of<TEnum> : null)
30+
*/
31+
public static function getNullableValue(?BackedEnum $enum): int|string|null
32+
{
33+
return $enum === null ? null : $enum->value;
34+
}
35+
}
36+
37+
assertType("2", EnumMethods::getValue(IntEnum::B));
38+
assertType("2", EnumMethods::getNullableValue(IntEnum::B));

0 commit comments

Comments
 (0)