Skip to content

Commit d640235

Browse files
authored
Merge pull request #9067 from weirdan/backed-enum-cases
fix `I::cases()` where `interface I extends BackedEnum`
2 parents 1350992 + afb8c88 commit d640235

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

stubs/Php81.phpstub

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ namespace {
2626
* @psalm-pure
2727
*/
2828
public static function tryFrom(string|int $value): ?static;
29+
30+
/**
31+
* @psalm-pure
32+
* @return list<static>
33+
*/
34+
public static function cases(): array;
2935
}
3036

3137
class ReflectionClass implements Reflector {

tests/EnumTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ enum Test: string
453453
'ignored_issues' => [],
454454
'php_version' => '8.1',
455455
],
456+
'methodInheritanceByInterfaces' => [
457+
'code' => '<?php
458+
interface I extends BackedEnum {}
459+
/** @var I $i */
460+
$a = $i::cases();
461+
$b = $i::from(1);
462+
$c = $i::tryFrom(2);
463+
',
464+
'assertions' => [
465+
'$a===' => 'list<I>',
466+
'$b===' => 'I',
467+
'$c===' => 'I|null',
468+
],
469+
'ignored_issues' => [],
470+
'php_version' => '8.1',
471+
],
456472
];
457473
}
458474

0 commit comments

Comments
 (0)