Skip to content

Commit

Permalink
Merge pull request #9092 from b2pweb/fix-8951-promoted-property-with-…
Browse files Browse the repository at this point in the history
…templace

Handle template type on promoted property
  • Loading branch information
orklah committed Jan 10, 2023
2 parents 9366c5e + e5f297d commit 4e64745
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 4e64745

Please sign in to comment.