Skip to content

Commit 47e49ed

Browse files
Fix phpstan/phpstan#9733: PHPDoc types from overridden function are not included in trait typeinfo when aliased (#5204)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dcdd6fa commit 47e49ed

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4298,9 +4298,10 @@ public function getPhpDocs(Scope $scope, Node\FunctionLike|Node\Stmt\Property $n
42984298
$docComment,
42994299
);
43004300
}
4301+
$methodNameForInheritance = $node->getAttribute('originalTraitMethodName') ?? $node->name->name;
43014302
$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForMethod(
43024303
$scope->getClassReflection(),
4303-
$node->name->name,
4304+
$methodNameForInheritance,
43044305
$currentResolvedPhpDoc,
43054306
$positionalParameterNames,
43064307
);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug9733;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
abstract class Base{
8+
/**
9+
* @param int[] $array
10+
*/
11+
abstract public function test(array $array) : void;
12+
}
13+
14+
trait MyTrait{
15+
public function test(array $array) : void{
16+
assertType('array<int>', $array);
17+
}
18+
}
19+
20+
class Concrete extends Base{
21+
use MyTrait {
22+
test as test2;
23+
}
24+
}

0 commit comments

Comments
 (0)