Skip to content

Commit

Permalink
Merge pull request #9067 from weirdan/backed-enum-cases
Browse files Browse the repository at this point in the history
fix `I::cases()` where `interface I extends BackedEnum`
  • Loading branch information
orklah committed Jan 7, 2023
2 parents 1350992 + afb8c88 commit d640235
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stubs/Php81.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ namespace {
* @psalm-pure
*/
public static function tryFrom(string|int $value): ?static;

/**
* @psalm-pure
* @return list<static>
*/
public static function cases(): array;
}

class ReflectionClass implements Reflector {
Expand Down
16 changes: 16 additions & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,22 @@ enum Test: string
'ignored_issues' => [],
'php_version' => '8.1',
],
'methodInheritanceByInterfaces' => [
'code' => '<?php
interface I extends BackedEnum {}
/** @var I $i */
$a = $i::cases();
$b = $i::from(1);
$c = $i::tryFrom(2);
',
'assertions' => [
'$a===' => 'list<I>',
'$b===' => 'I',
'$c===' => 'I|null',
],
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}

Expand Down

0 comments on commit d640235

Please sign in to comment.