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

fix: Handle template type on promoted property #8951

This commit is contained in:
Vincent QUATREVIEUX 2023-01-10 10:41:48 +01:00
parent 9366c5ed32
commit e5f297ddbb
2 changed files with 27 additions and 1 deletions

View File

@ -592,11 +592,15 @@ class FunctionLikeNodeScanner
$var_comment_readonly = false; $var_comment_readonly = false;
$var_comment_allow_private_mutation = false; $var_comment_allow_private_mutation = false;
if ($doc_comment) { if ($doc_comment) {
$template_types = ($this->existing_function_template_types ?: [])
+ ($classlike_storage->template_types ?: [])
;
$var_comments = CommentAnalyzer::getTypeFromComment( $var_comments = CommentAnalyzer::getTypeFromComment(
$doc_comment, $doc_comment,
$this->file_scanner, $this->file_scanner,
$this->aliases, $this->aliases,
$this->existing_function_template_types ?: [], $template_types,
$this->type_aliases, $this->type_aliases,
); );

View File

@ -4029,6 +4029,28 @@ class ClassTemplateTest extends TestCase
$baz = new DoesNotExist(); $baz = new DoesNotExist();
foobar($baz);', foobar($baz);',
], ],
'promoted property with template' => [
'code' => '<?php
/**
* @template T
*/
class A {
public function __construct(
/** @var T */
public mixed $t
) {}
}
$a = new A(5);
$t = $a->t;
',
'assertions' => [
'$a' => 'A<int>',
'$t' => 'int',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
]; ];
} }