Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle template type on promoted property #9092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -592,11 +592,15 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal
$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,
);

Expand Down
22 changes: 22 additions & 0 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -4029,6 +4029,28 @@ function foobar(DoesNotExist $baz): void {}
$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',
],
];
}

Expand Down