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:
parent
9366c5ed32
commit
e5f297ddbb
@ -592,11 +592,15 @@ class FunctionLikeNodeScanner
|
||||
$var_comment_readonly = false;
|
||||
$var_comment_allow_private_mutation = false;
|
||||
if ($doc_comment) {
|
||||
$template_types = ($this->existing_function_template_types ?: [])
|
||||
+ ($classlike_storage->template_types ?: [])
|
||||
;
|
||||
|
||||
$var_comments = CommentAnalyzer::getTypeFromComment(
|
||||
$doc_comment,
|
||||
$this->file_scanner,
|
||||
$this->aliases,
|
||||
$this->existing_function_template_types ?: [],
|
||||
$template_types,
|
||||
$this->type_aliases,
|
||||
);
|
||||
|
||||
|
@ -4029,6 +4029,28 @@ class ClassTemplateTest extends TestCase
|
||||
$baz = new DoesNotExist();
|
||||
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user