Skip to content

Commit

Permalink
Allow importing typedefs from enums
Browse files Browse the repository at this point in the history
Fixes #10416
  • Loading branch information
weirdan committed Jan 30, 2024
1 parent baa8660 commit 6d32d2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/TypeExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static function expandAtomic(
$declaring_fq_classlike_name = $self_class;
}

if (!($evaluate_class_constants && $codebase->classOrInterfaceExists($declaring_fq_classlike_name))) {
if (!($evaluate_class_constants && $codebase->classOrInterfaceOrEnumExists($declaring_fq_classlike_name))) {
return [$return_type];
}

Expand Down
19 changes: 19 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,25 @@ public function doesNotWork($_doesNotWork): void {
}
}',
],
'importFromEnum' => [
'code' => <<<'PHP'
<?php
/** @psalm-type _Foo = array{foo: string} */
enum E {}
/**
* @psalm-import-type _Foo from E
*/
class C {
/** @param _Foo $foo */
public function f(array $foo): void {
echo $foo['foo'];
}
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}

Expand Down

0 comments on commit 6d32d2f

Please sign in to comment.