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

Fix resolution of get_called_class

This commit is contained in:
Brown 2020-03-27 09:51:53 -04:00
parent 3253f57c94
commit ae31ec6805
3 changed files with 18 additions and 2 deletions

View File

@ -89,7 +89,12 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
]);
case 'get_called_class':
return new Type\Union([new Type\Atomic\TClassString($context->self ?: 'object')]);
return new Type\Union([
new Type\Atomic\TClassString(
$context->self ?: 'object',
$context->self ? new Type\Atomic\TNamedObject($context->self, true) : null
)
]);
case 'get_parent_class':
if ($context->self && $codebase->classExists($context->self)) {

View File

@ -28,13 +28,14 @@ class TNamedObject extends Atomic
/**
* @param string $value the name of the object
*/
public function __construct($value)
public function __construct($value, bool $was_static = false)
{
if ($value[0] === '\\') {
$value = substr($value, 1);
}
$this->value = $value;
$this->was_static = $was_static;
}
public function __toString()

View File

@ -738,6 +738,16 @@ class ClassStringTest extends TestCase
}
}'
],
'getCalledClassIsStaticClass' => [
'<?php
class A {
/** @return static */
public function getStatic() {
$c = get_called_class();
return new $c();
}
}'
],
];
}