1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Allow typedef imports from any classlike type

All we really need is for the source to be autoloadable, and it includes
all classlikes (interfaces, classes, enums and traits at the time of
writing).
This commit is contained in:
Bruce Weirdan 2024-01-31 23:07:23 +01:00
parent 9ec556bb14
commit 6140f6881c
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
3 changed files with 19 additions and 2 deletions

View File

@ -237,7 +237,7 @@ class FileAnalyzer extends SourceAnalyzer
$this->suppressed_issues,
new ClassLikeNameOptions(
true,
false,
true,
true,
true,
true,

View File

@ -283,7 +283,9 @@ final class TypeExpander
$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];
}

View File

@ -884,6 +884,21 @@ class TypeAnnotationTest extends TestCase
'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