Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow typedef imports from any kind of classlike #10625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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