1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #2192 - allow static return value on templated object

This commit is contained in:
Brown 2019-10-11 12:02:41 -04:00
parent 4ee037923a
commit 3f837a3493
3 changed files with 25 additions and 4 deletions

View File

@ -217,7 +217,10 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$codebase,
$context,
$lhs_type_part,
$lhs_type_part instanceof Type\Atomic\TNamedObject ? $lhs_type_part : null,
$lhs_type_part instanceof Type\Atomic\TNamedObject
|| $lhs_type_part instanceof Type\Atomic\TTemplateParam
? $lhs_type_part
: null,
$lhs_var_id,
$return_type,
$returns_by_ref,
@ -400,7 +403,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
* @param PhpParser\Node\Expr\MethodCall $stmt
* @param Codebase $codebase
* @param Context $context
* @param Type\Atomic $lhs_type_part
* @param Type\Atomic\TNamedObject|Type\Atomic\TTemplateParam $static_type
* @param ?string $lhs_var_id
* @param ?Type\Union &$return_type
* @param bool &$returns_by_ref
@ -419,7 +422,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
Codebase $codebase,
Context $context,
Type\Atomic $lhs_type_part,
?Type\Atomic\TNamedObject $static_type,
?Type\Atomic $static_type,
$lhs_var_id,
&$return_type,
&$returns_by_ref,

View File

@ -1764,7 +1764,7 @@ class ClassTemplateTest extends TestCase
return $bar->get();
}'
],
'templatedThing' => [
'templatedLiteralStringReplacement' => [
'<?php
/**
* @template T

View File

@ -781,6 +781,24 @@ class FunctionTemplateTest extends TestCase
$staticIdGenerator = idGenerator([Id::class, "fromString"]);
client($staticIdGenerator());'
],
'noCrashWhenTemplatedClassIsStatic' => [
'<?php
abstract class Model {
/** @return static */
public function newInstance() {
return new static();
}
}
/**
* @template T of Model
* @param T $m
* @return T
*/
function foo(Model $m) : Model {
return $m->newInstance();
}'
],
];
}