mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Support static return type
This commit is contained in:
parent
f34e54ec41
commit
99d6af0f9a
@ -3244,16 +3244,22 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
$this->codebase->scanner->queueClassLikeForScanning($type_string);
|
||||
$this->file_storage->referenced_classlikes[strtolower($type_string)] = $type_string;
|
||||
} else {
|
||||
$lower_hint = strtolower($hint->parts[0]);
|
||||
|
||||
if ($this->classlike_storages
|
||||
&& strtolower($hint->parts[0]) === 'self'
|
||||
&& ($lower_hint === 'self' || $lower_hint === 'static')
|
||||
&& !end($this->classlike_storages)->is_trait
|
||||
) {
|
||||
$type_string = $this->fq_classlike_names[count($this->fq_classlike_names) - 1];
|
||||
|
||||
if ($lower_hint === 'static') {
|
||||
$type_string .= '&static';
|
||||
}
|
||||
} else {
|
||||
$type_string = ClassLikeAnalyzer::getFQCLNFromNameObject($hint, $this->aliases);
|
||||
}
|
||||
|
||||
if (!in_array(strtolower($type_string), ['self', 'static', 'parent'], true)) {
|
||||
if (!in_array($lower_hint, ['self', 'static', 'parent'], true)) {
|
||||
$this->codebase->scanner->queueClassLikeForScanning($type_string);
|
||||
$this->file_storage->referenced_classlikes[strtolower($type_string)] = $type_string;
|
||||
}
|
||||
|
@ -863,6 +863,20 @@ class ReturnTypeTest extends TestCase
|
||||
return $a;
|
||||
}',
|
||||
],
|
||||
'returnStaticThis' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function getThis() : static {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public function foo() : void {}
|
||||
}
|
||||
|
||||
(new B)->getThis()->foo();',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user