Skip to content

Commit

Permalink
Merge pull request #7010 from weirdan/cases-in-wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Nov 28, 2021
2 parents 7660dc2 + ac903c5 commit 2df5f22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/Psalm/Internal/Type/TypeExpander.php
Expand Up @@ -215,9 +215,10 @@ public static function expandAtomic(
$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);

Expand All @@ -231,10 +232,6 @@ function ($constant_name) use ($const_name_part): bool {
);
}
} 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];
}

Expand Down
17 changes: 16 additions & 1 deletion tests/EnumTest.php
Expand Up @@ -154,7 +154,7 @@ public function get(): string
[],
'8.1'
],
'SKIPPED-wildcardEnum' => [
'wildcardEnumAsParam' => [
'<?php
enum A {
case C_1;
Expand All @@ -174,6 +174,21 @@ public static function foo(self $i) : void {}
[],
'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 {
Expand Down

0 comments on commit 2df5f22

Please sign in to comment.