Skip to content

Commit

Permalink
Merge pull request #10617 from weirdan/10416-import-typedefs-from-enums
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Jan 30, 2024
2 parents baa8660 + 6d32d2f commit 35e6eff
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 35e6eff

Please sign in to comment.