Skip to content

Commit

Permalink
Merge pull request #10625 from weirdan/allow-typedef-imports-from-any…
Browse files Browse the repository at this point in the history
…-kind-of-classlike
  • Loading branch information
weirdan committed Feb 1, 2024
2 parents 0082207 + 6140f68 commit 38d7d43
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/FileAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function analyze(
$this->suppressed_issues,
new ClassLikeNameOptions(
true,
false,
true,
true,
true,
true,
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Type/TypeExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ public static function expandAtomic(
$declaring_fq_classlike_name = $self_class;
}

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

Expand Down
15 changes: 15 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,21 @@ public function f(array $foo): void {
'ignored_issues' => [],
'php_version' => '8.1',
],
'importFromTrait' => [
'code' => <<<'PHP'
<?php
/** @psalm-type _Foo = array{foo: string} */
trait T {}
/** @psalm-import-type _Foo from T */
class C {
/** @param _Foo $foo */
public function f(array $foo): void {
echo $foo['foo'];
}
}
PHP,
],
'inlineComments' => [
'code' => <<<'PHP'
<?php
Expand Down

0 comments on commit 38d7d43

Please sign in to comment.