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

Do not override parent return type

This commit is contained in:
Brown 2019-03-28 10:43:49 -04:00
parent c022d49b1a
commit 937eb42e8b
2 changed files with 30 additions and 38 deletions

View File

@ -659,11 +659,7 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$found_generic_params = MethodCallAnalyzer::getClassTemplateParams(
$codebase,
$class_storage,
$stmt->class instanceof PhpParser\Node\Name
&& $stmt->class->parts === ['parent']
&& $context->self
? $context->self
: $fq_class_name,
$fq_class_name,
$method_name_lc,
$lhs_type_part,
null

View File

@ -1057,39 +1057,6 @@ class TemplateExtendsTest extends TestCase
}
}',
],
'extendsAndCallsParent' => [
'<?php
/**
* @template T
*/
abstract class Foo
{
/**
* @param T::class $str
*
* @return T::class
*/
public static function DoThing(string $str)
{
return $str;
}
}
/**
* @template-extends Foo<DateTimeInterface>
*/
class Bar extends Foo
{
/**
* @param class-string<DateTimeInterface> $str
*
* @return class-string<DateTimeInterface>
*/
public static function DoThing(string $str)
{
return parent::DoThing($str);
}
}',
],
'genericStaticAndSelf' => [
'<?php
/**
@ -1678,6 +1645,35 @@ class TemplateExtendsTest extends TestCase
ord((new Child())->example("str"));'
],
'allowWiderParentType' => [
'<?php
/**
* @template T
*/
abstract class Stringer {
/**
* @param T $t
*/
public static function getString($t, object $o = null) : string {
return "hello";
}
}
class A {}
/**
* @template-extends Stringer<A>
*/
class AStringer extends Stringer {
public static function getString($t, object $o = null) : string {
if ($o) {
return parent::getString($o);
}
return "a";
}
}'
],
];
}