1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #4107 - resolve reference to static in class constant

This commit is contained in:
Matthew Brown 2021-05-13 12:49:33 -04:00
parent cc7ff94f7c
commit 78ed9404cb
2 changed files with 17 additions and 1 deletions

View File

@ -188,6 +188,10 @@ class TypeExpander
$return_type->fq_classlike_name = $self_class;
}
if ($return_type->fq_classlike_name === 'static' && $self_class) {
$return_type->fq_classlike_name = is_string($static_class_type) ? $static_class_type : $self_class;
}
if ($evaluate_class_constants && $codebase->classOrInterfaceOrEnumExists($return_type->fq_classlike_name)) {
if (strtolower($return_type->const_name) === 'class') {
return new Type\Atomic\TLiteralClassString($return_type->fq_classlike_name);

View File

@ -1033,7 +1033,19 @@ class ConstantTest extends TestCase
'$dir===' => 'non-empty-string',
'$file===' => 'non-empty-string',
]
]
],
'noCrashWithStaticInDocblock' => [
'<?php
class Test {
const CONST1 = 1;
public function test(): void
{
/** @var static::CONST1 */
$a = static::CONST1;
}
}'
],
];
}