1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Include enum cases in const wildcards

Refs vimeo/psalm#6471
This commit is contained in:
Bruce Weirdan 2021-11-28 05:49:39 +02:00
parent 7660dc2f3e
commit ac903c5634
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 20 additions and 8 deletions

View File

@ -215,9 +215,10 @@ class TypeExpander
$class_storage = $codebase->classlike_storage_provider->get($return_type->fq_classlike_name);
if (strpos($return_type->const_name, '*') !== false) {
$class_storage = $codebase->classlike_storage_provider->get($return_type->fq_classlike_name);
$matching_constants = \array_keys($class_storage->constants);
$matching_constants = \array_merge(
\array_keys($class_storage->constants),
\array_keys($class_storage->enum_cases)
);
$const_name_part = \substr($return_type->const_name, 0, -1);
@ -231,10 +232,6 @@ class TypeExpander
);
}
} else {
if ($class_storage->is_enum) {
return new Type\Atomic\TEnumCase($return_type->fq_classlike_name, $return_type->const_name);
}
$matching_constants = [$return_type->const_name];
}

View File

@ -154,7 +154,7 @@ class EnumTest extends TestCase
[],
'8.1'
],
'SKIPPED-wildcardEnum' => [
'wildcardEnumAsParam' => [
'<?php
enum A {
case C_1;
@ -174,6 +174,21 @@ class EnumTest extends TestCase
[],
'8.1',
],
'wildcardEnumAsReturn' => [
'<?php
enum E {
const A = 1;
case B;
}
/** @return E::* */
function f(): mixed {
return E::B;
}',
'assertions' => [],
[],
'8.1',
],
'wildcardConstantsOnEnum' => [
'<?php
enum A {