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

Fix template default type issue

This commit is contained in:
Matthew Brown 2019-11-30 12:54:08 -05:00
parent b1e8c386fd
commit 088228f119
2 changed files with 33 additions and 4 deletions

View File

@ -1574,6 +1574,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_method = false)
{
$class_storage = null;
$fq_classlike_name = null;
if ($fake_method && $stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
$cased_function_id = '@method ' . $stmt->name->name;
@ -1803,7 +1804,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
continue;
}
$param_array = $this->getTranslatedFunctionParam($param, $stmt, $fake_method);
$param_array = $this->getTranslatedFunctionParam($param, $stmt, $fake_method, $fq_classlike_name);
if (isset($existing_params['$' . $param_array->name])) {
if (IssueBuffer::accepts(
@ -2691,7 +2692,8 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
public function getTranslatedFunctionParam(
PhpParser\Node\Param $param,
PhpParser\Node\FunctionLike $stmt,
bool $fake_method
bool $fake_method,
?string $fq_classlike_name
) : FunctionLikeParameter {
$param_type = null;
@ -2783,7 +2785,10 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
$this->codebase,
new \Psalm\Internal\Provider\NodeDataProvider(),
$param->default,
$this->aliases
$this->aliases,
null,
null,
$fq_classlike_name
)
: null
);

View File

@ -942,7 +942,7 @@ class ClassTemplateTest extends TestCase
'$e===' => 'E<string(bar)>',
],
],
'SKIPPED-templateDefaultClassConstant' => [
'SKIPPED-templateDefaultClassMemberConstant' => [
'<?php
class D {
const FOO = "bar";
@ -968,6 +968,30 @@ class ClassTemplateTest extends TestCase
'$e===' => 'E<string(bar)>',
],
],
'templateDefaultClassConstant' => [
'<?php
class D {}
/**
* @template T as object
*/
class E {
/** @var class-string<T> */
public $t;
/**
* @param class-string<T> $t
*/
function __construct(string $t = D::class) {
$this->t = $t;
}
}
$e = new E();',
'assertions' => [
'$e===' => 'E<D>',
],
],
'allowNullablePropertyAssignment' => [
'<?php
/**