mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #5070 – fix static return type inference in static methods
This commit is contained in:
parent
28d2795e59
commit
6f30399189
@ -299,7 +299,8 @@ class ExistingAtomicStaticCallAnalyzer
|
||||
true,
|
||||
false,
|
||||
\is_string($static_type)
|
||||
&& $static_type !== $context->self
|
||||
&& ($static_type !== $context->self
|
||||
|| $class_storage->final)
|
||||
);
|
||||
|
||||
$return_type_location = $codebase->methods->getMethodReturnTypeLocation(
|
||||
|
@ -165,6 +165,8 @@ class TypeExpander
|
||||
$return_type->extra_types[$extra_static_type->getKey()] = clone $extra_static_type;
|
||||
}
|
||||
}
|
||||
} elseif ($return_type->was_static && is_string($static_class_type) && $final) {
|
||||
$return_type->value = $static_class_type;
|
||||
} elseif ($self_class && $return_type_lc === 'self') {
|
||||
$return_type->value = $self_class;
|
||||
} elseif ($parent_class && $return_type_lc === 'parent') {
|
||||
|
@ -869,6 +869,40 @@ class MethodSignatureTest extends TestCase
|
||||
[],
|
||||
'7.4'
|
||||
],
|
||||
'extendStaticReturnTypeInFinal' => [
|
||||
'<?php
|
||||
final class B extends A
|
||||
{
|
||||
public static function doCretate1(): self
|
||||
{
|
||||
return self::create1();
|
||||
}
|
||||
|
||||
public static function doCretate2(): self
|
||||
{
|
||||
return self::create2();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A
|
||||
{
|
||||
final private function __construct() {}
|
||||
|
||||
final protected static function create1(): static
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
||||
/** @return static */
|
||||
final protected static function create2()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
}',
|
||||
[],
|
||||
[],
|
||||
'8.0'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user